bedrock.exceptions
This module contains all the exceptions that can be raised by Bedrock.
It surfaces all the exceptions in their submodules for shorter imports.
1""" 2This module contains all the exceptions that can be raised by Bedrock. 3 4It surfaces all the exceptions in their submodules for shorter imports. 5""" 6 7import bedrock.exceptions.bad_request_exception 8import bedrock.exceptions.bedrock_exception 9import bedrock.exceptions.conflicting_object_exception 10import bedrock.exceptions.forbidden_exception 11import bedrock.exceptions.not_found_exception 12import bedrock.exceptions.not_implemented_exception 13import bedrock.exceptions.object_validation_exception 14import bedrock.exceptions.unauthorised_exception 15import bedrock.exceptions.invalid_configuration_exception 16 17BadRequestException = bad_request_exception.BadRequestException 18BedrockException = bedrock_exception.BedrockException 19ConflictingObjectException = conflicting_object_exception.ConflictingObjectException 20ForbiddenException = forbidden_exception.ForbiddenException 21InvalidConfigurationException = invalid_configuration_exception.InvalidConfigurationException 22NotFoundException = not_found_exception.NotFoundException 23NotImplementedException = not_implemented_exception.NotImplementedException 24ObjectValidationException = object_validation_exception.ObjectValidationException 25UnauthorisedException = unauthorised_exception.UnauthorisedException
5class BadRequestException(BedrockException): # pragma: unit 6 """ 7 Throw this exception when the client has sent a bad request. 8 9 Default HTTP code: 400. 10 """ 11 def __init__(self, message="Bad request", exception=None): 12 super().__init__(message, exception, error_code=400)
Throw this exception when the client has sent a bad request.
Default HTTP code: 400.
Inherited Members
5class BedrockException(Exception): # pragma: unit 6 """ 7 A generic exception that can be thrown to return a user-friendly error to the client. 8 9 Default HTTP code: 500. 10 """ 11 def __init__(self, message, original_exception=None, error_code=500): 12 self.message = message 13 self.error_code = error_code 14 if original_exception is None: 15 self.original_exception = traceback.format_exc() 16 else: 17 self.original_exception = original_exception 18 super().__init__(self.message)
A generic exception that can be thrown to return a user-friendly error to the client.
Default HTTP code: 500.
11 def __init__(self, message, original_exception=None, error_code=500): 12 self.message = message 13 self.error_code = error_code 14 if original_exception is None: 15 self.original_exception = traceback.format_exc() 16 else: 17 self.original_exception = original_exception 18 super().__init__(self.message)
5class ConflictingObjectException(BedrockException): # pragma: unit 6 """ 7 Throw this exception when the client has sent a request that conflicts with an existing object. 8 9 Default HTTP code: 409. 10 """ 11 def __init__(self, cls, unique_identifiers): 12 unique_identifiers_string = ', '.join(unique_identifiers) 13 unique_identifiers_message = (f"{cls.__name__} requires each or a combination of {unique_identifiers_string}" 14 f" to be unique. ") 15 super().__init__(f"{cls.__name__} already exists. {unique_identifiers_message}", error_code=409)
Throw this exception when the client has sent a request that conflicts with an existing object.
Default HTTP code: 409.
11 def __init__(self, cls, unique_identifiers): 12 unique_identifiers_string = ', '.join(unique_identifiers) 13 unique_identifiers_message = (f"{cls.__name__} requires each or a combination of {unique_identifiers_string}" 14 f" to be unique. ") 15 super().__init__(f"{cls.__name__} already exists. {unique_identifiers_message}", error_code=409)
Inherited Members
5class ForbiddenException(BedrockException): # pragma: unit 6 """ 7 Throw this exception when the client is not authorised to access a resource but has provided valid credentials. 8 9 Default HTTP code: 403. 10 """ 11 def __init__(self, exception=None): 12 super().__init__("Forbidden", exception, error_code=403)
Throw this exception when the client is not authorised to access a resource but has provided valid credentials.
Default HTTP code: 403.
Inherited Members
5class InvalidConfigurationException(BedrockException): # pragma: unit 6 """ 7 Throw this exception when the application is missing config or has invalid config. 8 9 Default HTTP code: 500. 10 """ 11 invalid_items = [] 12 13 def __init__(self, invalid_items): 14 self.invalid_items = invalid_items 15 invalid_items_as_string = ", ".join(invalid_items) 16 super().__init__(f"Invalid configuration options: {invalid_items_as_string}", error_code=400)
Throw this exception when the application is missing config or has invalid config.
Default HTTP code: 500.
Inherited Members
5class NotFoundException(BedrockException): # pragma: unit 6 """ 7 Throw this exception when the client has requested a non-existing resource (or is not authorised to access it). 8 9 Default HTTP code: 404. 10 """ 11 def __init__(self, message="Resource not found", exception=None): 12 super().__init__(message, exception, error_code=404)
Throw this exception when the client has requested a non-existing resource (or is not authorised to access it).
Default HTTP code: 404.
Inherited Members
5class NotImplementedException(BedrockException): # pragma: unit 6 """ 7 Throw this exception when the client has requested a resource or action that is not implemented. 8 9 Default HTTP code: 501. 10 """ 11 def __init__(self, exception=None): 12 super().__init__("Not implemented", exception, error_code=501)
Throw this exception when the client has requested a resource or action that is not implemented.
Default HTTP code: 501.
Inherited Members
5class ObjectValidationException(BedrockException): # pragma: unit 6 """ 7 Throw this exception when the client has sent a request that doesn't pass validation (e.g. a body with nulls for 8 fields that are not nullable). 9 10 Default HTTP code: 400. 11 """ 12 invalid_items = [] 13 14 def __init__(self, cls, invalid_items): 15 self.invalid_items = invalid_items 16 invalid_items_as_string = ", ".join(invalid_items) 17 super().__init__(f"Invalid {cls.__name__} items: {invalid_items_as_string}", error_code=400)
Throw this exception when the client has sent a request that doesn't pass validation (e.g. a body with nulls for fields that are not nullable).
Default HTTP code: 400.