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
class BadRequestException(bedrock.exceptions.BedrockException):
 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.

BadRequestException(message='Bad request', exception=None)
11    def __init__(self, message="Bad request", exception=None):
12        super().__init__(message, exception, error_code=400)
Inherited Members
BedrockException
message
error_code
class BedrockException(builtins.Exception):
 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.

BedrockException(message, original_exception=None, error_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)
message
error_code
class ConflictingObjectException(bedrock.exceptions.BedrockException):
 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.

ConflictingObjectException(cls, unique_identifiers)
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
BedrockException
message
error_code
class ForbiddenException(bedrock.exceptions.BedrockException):
 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.

ForbiddenException(exception=None)
11    def __init__(self, exception=None):
12        super().__init__("Forbidden", exception, error_code=403)
Inherited Members
BedrockException
message
error_code
class InvalidConfigurationException(bedrock.exceptions.BedrockException):
 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.

InvalidConfigurationException(invalid_items)
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)
invalid_items = []
Inherited Members
BedrockException
message
error_code
class NotFoundException(bedrock.exceptions.BedrockException):
 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.

NotFoundException(message='Resource not found', exception=None)
11    def __init__(self, message="Resource not found", exception=None):
12        super().__init__(message, exception, error_code=404)
Inherited Members
BedrockException
message
error_code
class NotImplementedException(bedrock.exceptions.BedrockException):
 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.

NotImplementedException(exception=None)
11    def __init__(self, exception=None):
12        super().__init__("Not implemented", exception, error_code=501)
Inherited Members
BedrockException
message
error_code
class ObjectValidationException(bedrock.exceptions.BedrockException):
 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.

ObjectValidationException(cls, invalid_items)
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)
invalid_items = []
Inherited Members
BedrockException
message
error_code
class UnauthorisedException(bedrock.exceptions.BedrockException):
 5class UnauthorisedException(BedrockException):  # pragma: unit
 6    """
 7    Throw this exception when the client is not authorised to access a resource because it has not provided valid credentials.
 8
 9    Default HTTP code: 401.
10    """
11    def __init__(self, message="Unauthorised", exception=None):
12        super().__init__(message, exception, error_code=401)

Throw this exception when the client is not authorised to access a resource because it has not provided valid credentials.

Default HTTP code: 401.

UnauthorisedException(message='Unauthorised', exception=None)
11    def __init__(self, message="Unauthorised", exception=None):
12        super().__init__(message, exception, error_code=401)
Inherited Members
BedrockException
message
error_code