2021-11-17 17:19:03 +01:00
|
|
|
import json
|
2023-09-01 07:07:54 +00:00
|
|
|
from typing import Any, List, Tuple
|
2021-05-13 10:36:56 +01:00
|
|
|
|
2023-11-30 07:55:51 -08:00
|
|
|
from moto.core.exceptions import JsonRESTError
|
|
|
|
|
2021-05-13 10:36:56 +01:00
|
|
|
|
2022-10-16 12:06:23 +00:00
|
|
|
class ManagedBlockchainClientError(JsonRESTError):
|
2023-03-27 18:00:24 +01:00
|
|
|
def __init__(self, error_type: str, message: str):
|
2022-10-16 12:06:23 +00:00
|
|
|
super().__init__(error_type=error_type, message=message)
|
2021-05-13 10:36:56 +01:00
|
|
|
self.error_type = error_type
|
|
|
|
self.message = message
|
2021-11-17 17:19:03 +01:00
|
|
|
self.description = json.dumps({"message": self.message})
|
2021-05-13 10:36:56 +01:00
|
|
|
|
2023-03-27 18:00:24 +01:00
|
|
|
def get_headers(self, *args: Any, **kwargs: Any) -> List[Tuple[str, str]]: # pylint: disable=unused-argument
|
2021-05-13 10:36:56 +01:00
|
|
|
return [
|
|
|
|
("Content-Type", "application/json"),
|
|
|
|
("x-amzn-ErrorType", self.error_type),
|
|
|
|
]
|
|
|
|
|
2023-03-27 18:00:24 +01:00
|
|
|
def get_body(self, *args: Any, **kwargs: Any) -> str: # pylint: disable=unused-argument
|
2021-05-13 10:36:56 +01:00
|
|
|
return self.description
|
|
|
|
|
2020-05-03 18:13:40 -05:00
|
|
|
|
|
|
|
class BadRequestException(ManagedBlockchainClientError):
|
2023-03-27 18:00:24 +01:00
|
|
|
def __init__(self, pretty_called_method: str, operation_error: str):
|
2022-01-14 18:51:49 -01:00
|
|
|
super().__init__(
|
2020-05-03 18:13:40 -05:00
|
|
|
"BadRequestException",
|
2022-11-19 23:12:31 -01:00
|
|
|
f"An error occurred (BadRequestException) when calling the {pretty_called_method} operation: {operation_error}",
|
2020-05-03 18:13:40 -05:00
|
|
|
)
|
2020-05-06 21:54:59 -05:00
|
|
|
|
|
|
|
|
2020-05-13 06:28:22 -05:00
|
|
|
class InvalidRequestException(ManagedBlockchainClientError):
|
2023-03-27 18:00:24 +01:00
|
|
|
def __init__(self, pretty_called_method: str, operation_error: str):
|
2022-01-14 18:51:49 -01:00
|
|
|
super().__init__(
|
2020-05-13 06:28:22 -05:00
|
|
|
"InvalidRequestException",
|
2022-11-19 23:12:31 -01:00
|
|
|
f"An error occurred (InvalidRequestException) when calling the {pretty_called_method} operation: {operation_error}",
|
2020-05-13 06:28:22 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-05-06 21:54:59 -05:00
|
|
|
class ResourceNotFoundException(ManagedBlockchainClientError):
|
2023-03-27 18:00:24 +01:00
|
|
|
def __init__(self, pretty_called_method: str, operation_error: str):
|
2020-05-06 21:54:59 -05:00
|
|
|
self.code = 404
|
2022-01-14 18:51:49 -01:00
|
|
|
super().__init__(
|
2020-05-06 21:54:59 -05:00
|
|
|
"ResourceNotFoundException",
|
2022-11-19 23:12:31 -01:00
|
|
|
f"An error occurred (ResourceNotFoundException) when calling the {pretty_called_method} operation: {operation_error}",
|
2020-05-15 19:38:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ResourceAlreadyExistsException(ManagedBlockchainClientError):
|
2023-03-27 18:00:24 +01:00
|
|
|
def __init__(self, pretty_called_method: str, operation_error: str):
|
2020-05-15 19:38:19 -05:00
|
|
|
self.code = 409
|
2022-01-14 18:51:49 -01:00
|
|
|
super().__init__(
|
2020-05-15 19:38:19 -05:00
|
|
|
"ResourceAlreadyExistsException",
|
2022-11-19 23:12:31 -01:00
|
|
|
f"An error occurred (ResourceAlreadyExistsException) when calling the {pretty_called_method} operation: {operation_error}",
|
2020-05-06 21:54:59 -05:00
|
|
|
)
|
2020-05-13 06:28:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
class ResourceLimitExceededException(ManagedBlockchainClientError):
|
2023-03-27 18:00:24 +01:00
|
|
|
def __init__(self, pretty_called_method: str, operation_error: str):
|
2020-05-13 06:28:22 -05:00
|
|
|
self.code = 429
|
2022-01-14 18:51:49 -01:00
|
|
|
super().__init__(
|
2020-05-13 06:28:22 -05:00
|
|
|
"ResourceLimitExceededException",
|
2022-11-19 23:12:31 -01:00
|
|
|
f"An error occurred (ResourceLimitExceededException) when calling the {pretty_called_method} operation: {operation_error}",
|
2020-05-13 06:28:22 -05:00
|
|
|
)
|