File: exceptions.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (94 lines) | stat: -rw-r--r-- 2,766 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import json
from typing import Optional

from moto.core.exceptions import JsonRESTError


class IoTClientError(JsonRESTError):
    code = 400


class ResourceNotFoundException(IoTClientError):
    def __init__(self, msg: Optional[str] = None):
        self.code = 404
        super().__init__(
            "ResourceNotFoundException", msg or "The specified resource does not exist"
        )


class InvalidRequestException(IoTClientError):
    def __init__(self, msg: Optional[str] = None):
        self.code = 400
        super().__init__("InvalidRequestException", msg or "The request is not valid.")


class InvalidStateTransitionException(IoTClientError):
    def __init__(self, msg: Optional[str] = None):
        self.code = 409
        super().__init__(
            "InvalidStateTransitionException",
            msg or "An attempt was made to change to an invalid state.",
        )


class VersionConflictException(IoTClientError):
    def __init__(self, name: str):
        self.code = 409
        super().__init__(
            "VersionConflictException",
            f"The version for thing {name} does not match the expected version.",
        )


class CertificateStateException(IoTClientError):
    def __init__(self, msg: str, cert_id: str):
        self.code = 406
        super().__init__("CertificateStateException", f"{msg} Id: {cert_id}")


class DeleteConflictException(IoTClientError):
    def __init__(self, msg: str):
        self.code = 409
        super().__init__("DeleteConflictException", msg)


class ResourceAlreadyExistsException(IoTClientError):
    def __init__(self, msg: str, resource_id: str, resource_arn: str):
        self.code = 409
        super().__init__(
            "ResourceAlreadyExistsException", msg or "The resource already exists."
        )
        self.description = json.dumps(
            {
                "message": self.message,
                "resourceId": resource_id,
                "resourceArn": resource_arn,
            }
        )


class VersionsLimitExceededException(IoTClientError):
    def __init__(self, name: str):
        self.code = 409
        super().__init__(
            "VersionsLimitExceededException",
            f"The policy {name} already has the maximum number of versions (5)",
        )


class ThingStillAttached(IoTClientError):
    def __init__(self, name: str):
        self.code = 409
        super().__init__(
            "InvalidRequestException",
            f"Cannot delete. Thing {name} is still attached to one or more principals",
        )


class ConflictException(IoTClientError):
    def __init__(self, name: str):
        self.code = 409
        super().__init__(
            "ConflictException",
            f"A resource {name} already exists.",
        )