Merge pull request #3439 from bblommers/techdebt-remove-duplicate-awserrors

Tech Debt - Remove duplicate AWSError classes
This commit is contained in:
Steve Pulec 2020-11-09 19:59:02 -06:00 committed by GitHub
commit 47dbad291e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 31 additions and 129 deletions

View File

@ -1,9 +1,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re import re
import json
import datetime import datetime
from moto.core import BaseBackend, BaseModel from moto.core import BaseBackend, BaseModel
from moto.core.exceptions import AWSError
from moto.ec2 import ec2_backends from moto.ec2 import ec2_backends
from .utils import make_arn_for_certificate 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()) 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): class AWSValidationException(AWSError):
TYPE = "ValidationException" TYPE = "ValidationException"

View File

@ -1,24 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json
from moto.core.exceptions import JsonRESTError 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): class AWSValidationException(JsonRESTError):
def __init__(self, message, **kwargs): def __init__(self, message, **kwargs):
super(AWSValidationException, self).__init__( super(AWSValidationException, self).__init__(

View File

@ -1,40 +1,24 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json from moto.core.exceptions import AWSError
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): class InvalidRequestException(AWSError):
CODE = "InvalidRequestException" TYPE = "InvalidRequestException"
class InvalidParameterValueException(AWSError): class InvalidParameterValueException(AWSError):
CODE = "InvalidParameterValue" TYPE = "InvalidParameterValue"
class ValidationError(AWSError): class ValidationError(AWSError):
CODE = "ValidationError" TYPE = "ValidationError"
class InternalFailure(AWSError): class InternalFailure(AWSError):
CODE = "InternalFailure" TYPE = "InternalFailure"
STATUS = 500 STATUS = 500
class ClientException(AWSError): class ClientException(AWSError):
CODE = "ClientException" TYPE = "ClientException"
STATUS = 400 STATUS = 400

View File

@ -2,6 +2,7 @@ from __future__ import unicode_literals
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException
from jinja2 import DictLoader, Environment from jinja2 import DictLoader, Environment
import json
SINGLE_ERROR_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?> 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): class InvalidNextTokenException(JsonRESTError):
"""For AWS Config resource listing. This will be used by many different resource types, and so it is in moto.core.""" """For AWS Config resource listing. This will be used by many different resource types, and so it is in moto.core."""

View File

@ -1,22 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json from moto.core.exceptions import AWSError
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 InvalidInputException(AWSError): class InvalidInputException(AWSError):

View File

@ -1,5 +1,4 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json
from moto.core.exceptions import RESTError, JsonRESTError from moto.core.exceptions import RESTError, JsonRESTError
ERROR_WITH_MODEL_NAME = """{% extends 'single_error' %} 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): class ValidationError(JsonRESTError):
def __init__(self, message, **kwargs): def __init__(self, message, **kwargs):
super(ValidationError, self).__init__("ValidationException", message, **kwargs) super(ValidationError, self).__init__("ValidationException", message, **kwargs)

View File

@ -2,9 +2,9 @@ from __future__ import unicode_literals
import json import json
from moto.core.exceptions import AWSError
from moto.core.responses import BaseResponse from moto.core.responses import BaseResponse
from moto.core.utils import amzn_request_id from moto.core.utils import amzn_request_id
from .exceptions import AWSError
from .models import sagemaker_backends from .models import sagemaker_backends

View File

@ -1,21 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json from moto.core.exceptions import AWSError
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 ExecutionAlreadyExists(AWSError): class ExecutionAlreadyExists(AWSError):

View File

@ -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): class BadSegmentException(Exception):
def __init__(self, seg_id=None, code=None, message=None): def __init__(self, seg_id=None, code=None, message=None):
self.id = seg_id self.id = seg_id

View File

@ -6,7 +6,8 @@ import datetime
from collections import defaultdict from collections import defaultdict
import json import json
from moto.core import BaseBackend, BaseModel from moto.core import BaseBackend, BaseModel
from .exceptions import BadSegmentException, AWSError from moto.core.exceptions import AWSError
from .exceptions import BadSegmentException
class TelemetryRecords(BaseModel): class TelemetryRecords(BaseModel):

View File

@ -3,10 +3,11 @@ import json
import datetime import datetime
from moto.core.responses import BaseResponse from moto.core.responses import BaseResponse
from moto.core.exceptions import AWSError
from six.moves.urllib.parse import urlsplit from six.moves.urllib.parse import urlsplit
from .models import xray_backends from .models import xray_backends
from .exceptions import AWSError, BadSegmentException from .exceptions import BadSegmentException
class XRayResponse(BaseResponse): class XRayResponse(BaseResponse):