Merge pull request #3439 from bblommers/techdebt-remove-duplicate-awserrors
Tech Debt - Remove duplicate AWSError classes
This commit is contained in:
commit
47dbad291e
@ -1,9 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import json
|
||||
import datetime
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.exceptions import AWSError
|
||||
from moto.ec2 import ec2_backends
|
||||
|
||||
from .utils import make_arn_for_certificate
|
||||
@ -50,18 +50,6 @@ def datetime_to_epoch(date):
|
||||
return int((date - datetime.datetime(1970, 1, 1)).total_seconds())
|
||||
|
||||
|
||||
class AWSError(Exception):
|
||||
TYPE = None
|
||||
STATUS = 400
|
||||
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
def response(self):
|
||||
resp = {"__type": self.TYPE, "message": self.message}
|
||||
return json.dumps(resp), dict(status=self.STATUS)
|
||||
|
||||
|
||||
class AWSValidationException(AWSError):
|
||||
TYPE = "ValidationException"
|
||||
|
||||
|
@ -1,24 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import json
|
||||
from moto.core.exceptions import JsonRESTError
|
||||
|
||||
|
||||
class AWSError(Exception):
|
||||
""" Copied from acm/models.py; this class now exists in >5 locations,
|
||||
maybe this should be centralised for use by any module?
|
||||
"""
|
||||
|
||||
TYPE = None
|
||||
STATUS = 400
|
||||
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
def response(self):
|
||||
resp = {"__type": self.TYPE, "message": self.message}
|
||||
return json.dumps(resp), dict(status=self.STATUS)
|
||||
|
||||
|
||||
class AWSValidationException(JsonRESTError):
|
||||
def __init__(self, message, **kwargs):
|
||||
super(AWSValidationException, self).__init__(
|
||||
|
@ -1,40 +1,24 @@
|
||||
from __future__ import unicode_literals
|
||||
import json
|
||||
|
||||
|
||||
class AWSError(Exception):
|
||||
CODE = None
|
||||
STATUS = 400
|
||||
|
||||
def __init__(self, message, code=None, status=None):
|
||||
self.message = message
|
||||
self.code = code if code is not None else self.CODE
|
||||
self.status = status if status is not None else self.STATUS
|
||||
|
||||
def response(self):
|
||||
return (
|
||||
json.dumps({"__type": self.code, "message": self.message}),
|
||||
dict(status=self.status),
|
||||
)
|
||||
from moto.core.exceptions import AWSError
|
||||
|
||||
|
||||
class InvalidRequestException(AWSError):
|
||||
CODE = "InvalidRequestException"
|
||||
TYPE = "InvalidRequestException"
|
||||
|
||||
|
||||
class InvalidParameterValueException(AWSError):
|
||||
CODE = "InvalidParameterValue"
|
||||
TYPE = "InvalidParameterValue"
|
||||
|
||||
|
||||
class ValidationError(AWSError):
|
||||
CODE = "ValidationError"
|
||||
TYPE = "ValidationError"
|
||||
|
||||
|
||||
class InternalFailure(AWSError):
|
||||
CODE = "InternalFailure"
|
||||
TYPE = "InternalFailure"
|
||||
STATUS = 500
|
||||
|
||||
|
||||
class ClientException(AWSError):
|
||||
CODE = "ClientException"
|
||||
TYPE = "ClientException"
|
||||
STATUS = 400
|
||||
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from jinja2 import DictLoader, Environment
|
||||
import json
|
||||
|
||||
|
||||
SINGLE_ERROR_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -109,6 +110,22 @@ class AuthFailureError(RESTError):
|
||||
)
|
||||
|
||||
|
||||
class AWSError(Exception):
|
||||
TYPE = None
|
||||
STATUS = 400
|
||||
|
||||
def __init__(self, message, type=None, status=None):
|
||||
self.message = message
|
||||
self.type = type if type is not None else self.TYPE
|
||||
self.status = status if status is not None else self.STATUS
|
||||
|
||||
def response(self):
|
||||
return (
|
||||
json.dumps({"__type": self.type, "message": self.message}),
|
||||
dict(status=self.status),
|
||||
)
|
||||
|
||||
|
||||
class InvalidNextTokenException(JsonRESTError):
|
||||
"""For AWS Config resource listing. This will be used by many different resource types, and so it is in moto.core."""
|
||||
|
||||
|
@ -1,22 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class AWSError(Exception):
|
||||
TYPE = None
|
||||
STATUS = 400
|
||||
|
||||
def __init__(self, message, type=None, status=None):
|
||||
self.message = message
|
||||
self.type = type if type is not None else self.TYPE
|
||||
self.status = status if status is not None else self.STATUS
|
||||
|
||||
def response(self):
|
||||
return (
|
||||
json.dumps({"__type": self.type, "message": self.message}),
|
||||
dict(status=self.status),
|
||||
)
|
||||
from moto.core.exceptions import AWSError
|
||||
|
||||
|
||||
class InvalidInputException(AWSError):
|
||||
|
@ -1,5 +1,4 @@
|
||||
from __future__ import unicode_literals
|
||||
import json
|
||||
from moto.core.exceptions import RESTError, JsonRESTError
|
||||
|
||||
ERROR_WITH_MODEL_NAME = """{% extends 'single_error' %}
|
||||
@ -30,22 +29,6 @@ class MissingModel(ModelError):
|
||||
)
|
||||
|
||||
|
||||
class AWSError(Exception):
|
||||
TYPE = None
|
||||
STATUS = 400
|
||||
|
||||
def __init__(self, message, type=None, status=None):
|
||||
self.message = message
|
||||
self.type = type if type is not None else self.TYPE
|
||||
self.status = status if status is not None else self.STATUS
|
||||
|
||||
def response(self):
|
||||
return (
|
||||
json.dumps({"__type": self.type, "message": self.message}),
|
||||
dict(status=self.status),
|
||||
)
|
||||
|
||||
|
||||
class ValidationError(JsonRESTError):
|
||||
def __init__(self, message, **kwargs):
|
||||
super(ValidationError, self).__init__("ValidationException", message, **kwargs)
|
||||
|
@ -2,9 +2,9 @@ from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from moto.core.exceptions import AWSError
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.utils import amzn_request_id
|
||||
from .exceptions import AWSError
|
||||
from .models import sagemaker_backends
|
||||
|
||||
|
||||
|
@ -1,21 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
import json
|
||||
|
||||
|
||||
class AWSError(Exception):
|
||||
TYPE = None
|
||||
STATUS = 400
|
||||
|
||||
def __init__(self, message, type=None, status=None):
|
||||
self.message = message
|
||||
self.type = type if type is not None else self.TYPE
|
||||
self.status = status if status is not None else self.STATUS
|
||||
|
||||
def response(self):
|
||||
return (
|
||||
json.dumps({"__type": self.type, "message": self.message}),
|
||||
dict(status=self.status),
|
||||
)
|
||||
from moto.core.exceptions import AWSError
|
||||
|
||||
|
||||
class ExecutionAlreadyExists(AWSError):
|
||||
|
@ -1,26 +1,3 @@
|
||||
import json
|
||||
|
||||
|
||||
class AWSError(Exception):
|
||||
CODE = None
|
||||
STATUS = 400
|
||||
|
||||
def __init__(self, message, code=None, status=None):
|
||||
self.message = message
|
||||
self.code = code if code is not None else self.CODE
|
||||
self.status = status if status is not None else self.STATUS
|
||||
|
||||
def response(self):
|
||||
return (
|
||||
json.dumps({"__type": self.code, "message": self.message}),
|
||||
dict(status=self.status),
|
||||
)
|
||||
|
||||
|
||||
class InvalidRequestException(AWSError):
|
||||
CODE = "InvalidRequestException"
|
||||
|
||||
|
||||
class BadSegmentException(Exception):
|
||||
def __init__(self, seg_id=None, code=None, message=None):
|
||||
self.id = seg_id
|
||||
|
@ -6,7 +6,8 @@ import datetime
|
||||
from collections import defaultdict
|
||||
import json
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from .exceptions import BadSegmentException, AWSError
|
||||
from moto.core.exceptions import AWSError
|
||||
from .exceptions import BadSegmentException
|
||||
|
||||
|
||||
class TelemetryRecords(BaseModel):
|
||||
|
@ -3,10 +3,11 @@ import json
|
||||
import datetime
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from moto.core.exceptions import AWSError
|
||||
from six.moves.urllib.parse import urlsplit
|
||||
|
||||
from .models import xray_backends
|
||||
from .exceptions import AWSError, BadSegmentException
|
||||
from .exceptions import BadSegmentException
|
||||
|
||||
|
||||
class XRayResponse(BaseResponse):
|
||||
|
Loading…
Reference in New Issue
Block a user