Skip to content

Commit

Permalink
Fixes #69: Add additional http codes and statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
dolamroth authored and DmitryBurnaev committed Mar 14, 2023
1 parent 1f5487b commit d2fdf66
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
48 changes: 40 additions & 8 deletions starlette_web/common/http/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class HttpError(BaseApplicationError):
message = "Some HTTP error happened."


class InvalidParameterError(BaseApplicationError):
status_code = 400
message = "Requested data is not valid."
response_status = ResponseStatus.INVALID_PARAMETERS


class AuthenticationFailedError(BaseApplicationError):
status_code = 401
response_status = ResponseStatus.AUTH_FAILED
Expand All @@ -57,6 +63,12 @@ class SignatureExpiredError(AuthenticationFailedError):
message = "Authentication credentials are invalid."


class InviteTokenInvalidationError(BaseApplicationError):
status_code = 401
message = "Requested token is expired or does not exist."
response_status = ResponseStatus.INVITE_ERROR


class PermissionDeniedError(BaseApplicationError):
status_code = 403
message = "You don't have permission to perform this action."
Expand All @@ -75,23 +87,43 @@ class MethodNotAllowedError(BaseApplicationError):
response_status = ResponseStatus.NOT_ALLOWED


class InviteTokenInvalidationError(BaseApplicationError):
status_code = 401
message = "Requested token is expired or does not exist."
response_status = ResponseStatus.INVITE_ERROR
class NotAcceptableError(BaseApplicationError):
status_code = 406
message = (
"Request cannot be processed, "
"Accept-* headers are incompatible with server."
)
response_status = ResponseStatus.NOT_ALLOWED


class InvalidParameterError(BaseApplicationError):
status_code = 400
message = "Requested data is not valid."
response_status = ResponseStatus.INVALID_PARAMETERS
class ConflictError(BaseApplicationError):
status_code = 409
message = "Request conflicts with current state of server."
response_status = ResponseStatus.CONFLICT


class ImATeapotError(BaseApplicationError):
status_code = 418
message = "The server cannot brew a coffee, because it is a teapot."
response_status = ResponseStatus.I_AM_A_TEAPOT


class UnprocessableEntryError(BaseApplicationError):
status_code = 422
message = "Could not process request due to logical errors in data."
response_status = ResponseStatus.UNPROCESSABLE_ENTRY


class InvalidResponseError(BaseApplicationError):
status_code = 500
message = "Response data couldn't be serialized."


class NotImplementedByServerError(BaseApplicationError):
status_code = 501
message = "Functionality is not supported by the server."


class SendRequestError(BaseApplicationError):
status_code = 503
message = "Got unexpected error for sending request."
Expand Down
20 changes: 16 additions & 4 deletions starlette_web/common/http/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@


class ResponseStatus(TextChoices):
# 2xx
OK = "OK"
INTERNAL_ERROR = "INTERNAL_ERROR"
CREATED = "CREATED"
ACCEPTED = "ACCEPTED"
NO_CONTENT = "NO_CONTENT"

# 4xx
INVALID_PARAMETERS = "INVALID_PARAMETERS"
AUTH_FAILED = "AUTH_FAILED"
MISSED_CREDENTIALS = "MISSED_CREDENTIALS"
SIGNATURE_EXPIRED = "SIGNATURE_EXPIRED"
NOT_FOUND = "NOT_FOUND"
NOT_ALLOWED = "NOT_ALLOWED"
INVITE_ERROR = "INVITE_ERROR"
INVALID_PARAMETERS = "INVALID_PARAMETERS"
FORBIDDEN = "FORBIDDEN"
NOT_FOUND = "NOT_FOUND"
NOT_ALLOWED = "NOT_ALLOWED"
NOT_ACCEPTABLE = "NOT_ACCEPTABLE"
CONFLICT = "CONFLICT"
I_AM_A_TEAPOT = "I_AM_A_TEAPOT"
UNPROCESSABLE_ENTRY = "UNPROCESSABLE_ENTRY"

# 5xx
INTERNAL_ERROR = "INTERNAL_ERROR"
SERVICE_COMMUNICATION_ERROR = "SERVICE_COMMUNICATION_ERROR"


Expand Down

0 comments on commit d2fdf66

Please sign in to comment.