exceptions
roblox.utilities.exceptions
¶
Contains exceptions used by ro.py.
AssetNotFound (ItemNotFound)
¶
Raised for invalid asset IDs.
Source code in roblox/utilities/exceptions.py
class AssetNotFound(ItemNotFound):
"""
Raised for invalid asset IDs.
"""
pass
BadRequest (HTTPException)
¶
HTTP exception raised for status code 400.
Source code in roblox/utilities/exceptions.py
class BadRequest(HTTPException):
"""HTTP exception raised for status code 400."""
pass
BadgeNotFound (ItemNotFound)
¶
Raised for invalid badge IDs.
Source code in roblox/utilities/exceptions.py
class BadgeNotFound(ItemNotFound):
"""
Raised for invalid badge IDs.
"""
pass
Forbidden (HTTPException)
¶
HTTP exception raised for status code 403. This usually means the X-CSRF-Token was not properly provided.
Source code in roblox/utilities/exceptions.py
class Forbidden(HTTPException):
"""HTTP exception raised for status code 403. This usually means the X-CSRF-Token was not properly provided."""
pass
GroupNotFound (ItemNotFound)
¶
Raised for invalid badge IDs.
Source code in roblox/utilities/exceptions.py
class GroupNotFound(ItemNotFound):
"""
Raised for invalid badge IDs.
"""
pass
HTTPException (RobloxException)
¶
Exception that's raised when an HTTP request fails.
Attributes:
Name | Type | Description |
---|---|---|
response |
Response |
The HTTP response object. |
status |
int |
The HTTP response status code. |
errors |
List[ResponseError] |
A list of Roblox response errors. |
Source code in roblox/utilities/exceptions.py
class HTTPException(RobloxException):
"""
Exception that's raised when an HTTP request fails.
Attributes:
response: The HTTP response object.
status: The HTTP response status code.
errors: A list of Roblox response errors.
"""
def __init__(self, response: Response, errors: Optional[list] = None):
"""
Arguments:
response: The raw response object.
errors: A list of errors.
"""
self.response: Response = response
self.status: int = response.status_code
self.errors: List[ResponseError]
if errors:
self.errors = [
ResponseError(data=error_data) for error_data in errors
]
else:
self.errors = []
if self.errors:
error_string = self._generate_string()
super().__init__(
f"{response.status_code} {response.reason_phrase}: {response.url}.\n\nErrors:\n{error_string}")
else:
super().__init__(f"{response.status_code} {response.reason_phrase}: {response.url}")
def _generate_string(self) -> str:
parsed_errors = []
for error in self.errors:
# Make each error into a parsed string
parsed_error = f"\t{error.code}: {error.message}"
error_messages = []
error.user_facing_message and error_messages.append(f"User-facing message: {error.user_facing_message}")
error.field and error_messages.append(f"Field: {error.field}")
error.retryable and error_messages.append(f"Retryable: {error.retryable}")
if error_messages:
error_message_string = "\n\t\t".join(error_messages)
parsed_error += f"\n\t\t{error_message_string}"
parsed_errors.append(parsed_error)
# Turn the parsed errors into a joined string
return "\n".join(parsed_errors)
__init__(self, response: Response, errors: Optional[list] = None)
special
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
Response |
The raw response object. |
required |
errors |
Optional[list] |
A list of errors. |
None |
Source code in roblox/utilities/exceptions.py
def __init__(self, response: Response, errors: Optional[list] = None):
"""
Arguments:
response: The raw response object.
errors: A list of errors.
"""
self.response: Response = response
self.status: int = response.status_code
self.errors: List[ResponseError]
if errors:
self.errors = [
ResponseError(data=error_data) for error_data in errors
]
else:
self.errors = []
if self.errors:
error_string = self._generate_string()
super().__init__(
f"{response.status_code} {response.reason_phrase}: {response.url}.\n\nErrors:\n{error_string}")
else:
super().__init__(f"{response.status_code} {response.reason_phrase}: {response.url}")
InternalServerError (HTTPException)
¶
HTTP exception raised for status code 500. This usually means that there was an issue on Roblox's end, but due to faulty coding on Roblox's part this can sometimes mean that an endpoint used internally was disabled or that invalid parameters were passed.
Source code in roblox/utilities/exceptions.py
class InternalServerError(HTTPException):
"""
HTTP exception raised for status code 500.
This usually means that there was an issue on Roblox's end, but due to faulty coding on Roblox's part this can
sometimes mean that an endpoint used internally was disabled or that invalid parameters were passed.
"""
pass
InvalidRole (RobloxException)
¶
Raised when a role doesn't exist.
Source code in roblox/utilities/exceptions.py
class InvalidRole(RobloxException):
"""
Raised when a role doesn't exist.
"""
pass
ItemNotFound (RobloxException)
¶
Raised for invalid items.
Source code in roblox/utilities/exceptions.py
class ItemNotFound(RobloxException):
"""
Raised for invalid items.
"""
def __init__(self, message: str, response: Optional[Response] = None):
"""
Arguments:
response: The raw response object.
"""
self.response: Optional[Response] = response
self.status: Optional[int] = response.status_code if response else None
super().__init__(message)
__init__(self, message: str, response: Optional[httpx.Response] = None)
special
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response |
Optional[httpx.Response] |
The raw response object. |
None |
Source code in roblox/utilities/exceptions.py
def __init__(self, message: str, response: Optional[Response] = None):
"""
Arguments:
response: The raw response object.
"""
self.response: Optional[Response] = response
self.status: Optional[int] = response.status_code if response else None
super().__init__(message)
NoMoreItems (RobloxException)
¶
Raised when there are no more items left to iterate through.
Source code in roblox/utilities/exceptions.py
class NoMoreItems(RobloxException):
"""
Raised when there are no more items left to iterate through.
"""
pass
NotFound (HTTPException)
¶
HTTP exception raised for status code 404. This usually means we have an internal URL issue - please make a GitHub issue about this!
Source code in roblox/utilities/exceptions.py
class NotFound(HTTPException):
"""
HTTP exception raised for status code 404.
This usually means we have an internal URL issue - please make a GitHub issue about this!
"""
pass
PlaceNotFound (ItemNotFound)
¶
Raised for invalid place IDs.
Source code in roblox/utilities/exceptions.py
class PlaceNotFound(ItemNotFound):
"""
Raised for invalid place IDs.
"""
pass
PluginNotFound (ItemNotFound)
¶
Raised for invalid plugin IDs.
Source code in roblox/utilities/exceptions.py
class PluginNotFound(ItemNotFound):
"""
Raised for invalid plugin IDs.
"""
pass
ResponseError
¶
Represents an error returned by a Roblox game server.
Attributes:
Name | Type | Description |
---|---|---|
code |
int |
The error code. |
message |
Optional[str] |
The error message. |
user_facing_message |
Optional[str] |
A more simple error message intended for frontend use. |
field |
Optional[str] |
The field causing this error. |
retryable |
Optional[str] |
Whether retrying this exception could supress this issue. |
Source code in roblox/utilities/exceptions.py
class ResponseError:
"""
Represents an error returned by a Roblox game server.
Attributes:
code: The error code.
message: The error message.
user_facing_message: A more simple error message intended for frontend use.
field: The field causing this error.
retryable: Whether retrying this exception could supress this issue.
"""
def __init__(self, data: dict):
self.code: int = data["code"]
self.message: Optional[str] = data.get("message")
self.user_facing_message: Optional[str] = data.get("userFacingMessage")
self.field: Optional[str] = data.get("field")
self.retryable: Optional[str] = data.get("retryable")
__init__(self, data: dict)
special
¶
Source code in roblox/utilities/exceptions.py
def __init__(self, data: dict):
self.code: int = data["code"]
self.message: Optional[str] = data.get("message")
self.user_facing_message: Optional[str] = data.get("userFacingMessage")
self.field: Optional[str] = data.get("field")
self.retryable: Optional[str] = data.get("retryable")
RobloxException (Exception)
¶
Base exception for all of ro.py.
Source code in roblox/utilities/exceptions.py
class RobloxException(Exception):
"""
Base exception for all of ro.py.
"""
pass
TooManyRequests (HTTPException)
¶
HTTP exception raised for status code 429. This means that Roblox has ratelimited you.
Source code in roblox/utilities/exceptions.py
class TooManyRequests(HTTPException):
"""
HTTP exception raised for status code 429.
This means that Roblox has [ratelimited](https://en.wikipedia.org/wiki/Rate_limiting) you.
"""
pass
Unauthorized (HTTPException)
¶
HTTP exception raised for status code 401. This usually means you aren't properly authenticated.
Source code in roblox/utilities/exceptions.py
class Unauthorized(HTTPException):
"""HTTP exception raised for status code 401. This usually means you aren't properly authenticated."""
UniverseNotFound (ItemNotFound)
¶
Raised for invalid universe IDs.
Source code in roblox/utilities/exceptions.py
class UniverseNotFound(ItemNotFound):
"""
Raised for invalid universe IDs.
"""
pass
UserNotFound (ItemNotFound)
¶
Raised for invalid user IDs or usernames.
Source code in roblox/utilities/exceptions.py
class UserNotFound(ItemNotFound):
"""
Raised for invalid user IDs or usernames.
"""
pass
get_exception_from_status_code(code: int) -> Type[roblox.utilities.exceptions.HTTPException]
¶
Gets an exception that should be raised instead of the generic HTTPException for this status code.
Source code in roblox/utilities/exceptions.py
def get_exception_from_status_code(code: int) -> Type[HTTPException]:
"""
Gets an exception that should be raised instead of the generic HTTPException for this status code.
"""
return _codes_exceptions.get(code) or HTTPException