1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import json
from typing import Any
from moto.core.exceptions import JsonRESTError
class ManagedBlockchainClientError(JsonRESTError):
def __init__(self, error_type: str, message: str):
super().__init__(error_type=error_type, message=message)
self.error_type = error_type
self.message = message
self.description = json.dumps({"message": self.message})
def get_headers(self, *args: Any, **kwargs: Any) -> list[tuple[str, str]]:
return [
("Content-Type", "application/json"),
("x-amzn-ErrorType", self.error_type),
]
def get_body(self, *args: Any, **kwargs: Any) -> str:
return self.description
class BadRequestException(ManagedBlockchainClientError):
def __init__(self, pretty_called_method: str, operation_error: str):
super().__init__(
"BadRequestException",
f"An error occurred (BadRequestException) when calling the {pretty_called_method} operation: {operation_error}",
)
class InvalidRequestException(ManagedBlockchainClientError):
def __init__(self, pretty_called_method: str, operation_error: str):
super().__init__(
"InvalidRequestException",
f"An error occurred (InvalidRequestException) when calling the {pretty_called_method} operation: {operation_error}",
)
class ResourceNotFoundException(ManagedBlockchainClientError):
def __init__(self, pretty_called_method: str, operation_error: str):
self.code = 404
super().__init__(
"ResourceNotFoundException",
f"An error occurred (ResourceNotFoundException) when calling the {pretty_called_method} operation: {operation_error}",
)
class ResourceAlreadyExistsException(ManagedBlockchainClientError):
def __init__(self, pretty_called_method: str, operation_error: str):
self.code = 409
super().__init__(
"ResourceAlreadyExistsException",
f"An error occurred (ResourceAlreadyExistsException) when calling the {pretty_called_method} operation: {operation_error}",
)
class ResourceLimitExceededException(ManagedBlockchainClientError):
def __init__(self, pretty_called_method: str, operation_error: str):
self.code = 429
super().__init__(
"ResourceLimitExceededException",
f"An error occurred (ResourceLimitExceededException) when calling the {pretty_called_method} operation: {operation_error}",
)
|