-
Notifications
You must be signed in to change notification settings - Fork 172
/
errors.py
200 lines (132 loc) · 5.06 KB
/
errors.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from typing import Type, Optional
class APNsException(Exception):
pass
class ConnectionFailed(APNsException):
"""There was an error connecting to APNs."""
class InternalException(APNsException):
"""This exception should not be raised. If it is, please report this as a bug."""
pass
class BadPayloadException(APNsException):
"""Something bad with the payload."""
pass
class BadCollapseId(BadPayloadException):
"""The collapse identifier exceeds the maximum allowed size"""
pass
class BadDeviceToken(APNsException):
"""The specified device token was bad.
Verify that the request contains a valid token and that the token matches the environment."""
pass
class BadExpirationDate(BadPayloadException):
"""The apns-expiration value is bad."""
pass
class BadMessageId(InternalException):
"""The apns-id value is bad."""
pass
class BadPriority(InternalException):
"""The apns-priority value is bad."""
pass
class BadTopic(BadPayloadException):
"""The apns-topic was invalid."""
pass
class DeviceTokenNotForTopic(APNsException):
"""The device token does not match the specified topic."""
class DuplicateHeaders(InternalException):
"""One or more headers were repeated."""
pass
class IdleTimeout(APNsException):
"""Idle time out."""
pass
class MissingDeviceToken(APNsException):
"""The device token is not specified in the request :path.
Verify that the :path header contains the device token."""
pass
class MissingTopic(BadPayloadException):
"""The apns-topic header of the request was not specified and was required.
The apns-topic header is mandatory when the client is connected using a certificate
that supports multiple topics."""
pass
class PayloadEmpty(BadPayloadException):
"""The message payload was empty."""
pass
class TopicDisallowed(BadPayloadException):
"""Pushing to this topic is not allowed."""
pass
class BadCertificate(APNsException):
"""The certificate was bad."""
pass
class BadCertificateEnvironment(APNsException):
"""The client certificate was for the wrong environment."""
pass
class ExpiredProviderToken(APNsException):
"""The provider token is stale and a new token should be generated."""
pass
class Forbidden(APNsException):
"""The specified action is not allowed."""
pass
class InvalidProviderToken(APNsException):
"""The provider token is not valid or the token signature could not be verified."""
pass
class MissingProviderToken(APNsException):
"""No provider certificate was used to connect to APNs and Authorization header was missing or no provider token
was specified. """
pass
class BadPath(APNsException):
"""The request contained a bad :path value."""
pass
class MethodNotAllowed(InternalException):
"""The specified :method was not POST."""
pass
class Unregistered(APNsException):
"""The device token is inactive for the specified topic."""
def __init__(self, timestamp: Optional[str] = None) -> None:
super(Unregistered, self).__init__()
self.timestamp = timestamp
class PayloadTooLarge(BadPayloadException):
"""The message payload was too large. The maximum payload size is 4096 bytes."""
pass
class TooManyProviderTokenUpdates(APNsException):
"""The provider token is being updated too often."""
pass
class TooManyRequests(APNsException):
"""Too many requests were made consecutively to the same device token."""
pass
class InternalServerError(APNsException):
"""An internal server error occurred."""
pass
class ServiceUnavailable(APNsException):
"""The service is unavailable."""
pass
class Shutdown(APNsException):
"""The server is shutting down."""
pass
def exception_class_for_reason(reason: str) -> Type[APNsException]:
return {
'BadCollapseId': BadCollapseId,
'BadDeviceToken': BadDeviceToken,
'BadExpirationDate': BadExpirationDate,
'BadMessageId': BadMessageId,
'BadPriority': BadPriority,
'BadTopic': BadTopic,
'DeviceTokenNotForTopic': DeviceTokenNotForTopic,
'DuplicateHeaders': DuplicateHeaders,
'IdleTimeout': IdleTimeout,
'MissingDeviceToken': MissingDeviceToken,
'MissingTopic': MissingTopic,
'PayloadEmpty': PayloadEmpty,
'TopicDisallowed': TopicDisallowed,
'BadCertificate': BadCertificate,
'BadCertificateEnvironment': BadCertificateEnvironment,
'ExpiredProviderToken': ExpiredProviderToken,
'Forbidden': Forbidden,
'InvalidProviderToken': InvalidProviderToken,
'MissingProviderToken': MissingProviderToken,
'BadPath': BadPath,
'MethodNotAllowed': MethodNotAllowed,
'Unregistered': Unregistered,
'PayloadTooLarge': PayloadTooLarge,
'TooManyProviderTokenUpdates': TooManyProviderTokenUpdates,
'TooManyRequests': TooManyRequests,
'InternalServerError': InternalServerError,
'ServiceUnavailable': ServiceUnavailable,
'Shutdown': Shutdown,
}[reason]