This repository was archived by the owner on May 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_exceptions.py
More file actions
235 lines (192 loc) · 9.69 KB
/
Copy pathcustom_exceptions.py
File metadata and controls
235 lines (192 loc) · 9.69 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
"""custom_exceptions.py: defines all the exceptions thrown by Just Landed."""
__author__ = "Jon Grall"
__copyright__ = "Copyright 2012, Just Landed LLC"
__email__ = "jon@littledetails.net"
###############################################################################
# Reporting Exceptions
###############################################################################
class ReportingServiceUnavailableError(Exception):
def __init__(self):
super(ReportingServiceUnavailableError, self).__init__()
self.message = 'Reporting service is unavailable.'
self.code = 503 # Service unavailable
class MixpanelUnavailableError(ReportingServiceUnavailableError):
def __init__(self):
super(MixpanelUnavailableError, self).__init__()
self.message = 'Mixpanel API is unavailable.'
class GoogleAnalyticsUnavailableError(ReportingServiceUnavailableError):
def __init__(self):
super(GoogleAnalyticsUnavailableError, self).__init__()
self.message = 'Google Analytics is unavailable.'
class ReportEventFailedException(Exception):
def __init__(self, status_code=403, event_name=''):
super(ReportEventFailedException, self).__init__()
self.message = 'Unable to report event: %s' % event_name
self.code = status_code
class EventClassNotFoundException(Exception):
def __init__(self, class_name=''):
super(EventClassNotFoundException, self).__init__()
self.message = 'Unable to report event with class: %s' % class_name
self.code = 400 # Bad request
class UnableToCreateUniqueEventKey(Exception):
def __init__(self, class_name=''):
super(UnableToCreateUniqueEventKey, self).__init__()
self.message = 'Unable to build key for unique %s event.' % class_name
self.code = 500 # Server error
###############################################################################
# Flight Data Source Exceptions
###############################################################################
class FlightDataUnavailableError(Exception):
def __init__(self):
super(FlightDataUnavailableError, self).__init__()
self.message = 'Flight datasource is unavailable.'
self.code = 503 # Service unavailable
class FlightAwareUnavailableError(FlightDataUnavailableError):
def __init__(self):
super(FlightAwareUnavailableError, self).__init__()
self.message = 'FlightAware API is unavailable.'
class InvalidFlightNumberException(Exception):
def __init__(self, flight_number=''):
super(InvalidFlightNumberException, self).__init__()
self.message = 'Invalid flight number: %s' % flight_number
self.code = 400 # Bad request
class FlightNotFoundException(Exception):
def __init__(self, flight=''):
super(FlightNotFoundException, self).__init__()
self.message = 'Flight not found: %s' % flight
self.code = 404 # Not found
class CurrentFlightNotFoundException(FlightNotFoundException):
def __init__(self, flight=''):
super(CurrentFlightNotFoundException, self).__init__()
self.message = 'No recent %s flights found.' % flight
class TerminalsUnknownException(Exception):
def __init__(self, flight_id=''):
super(TerminalsUnknownException, self).__init__()
self.message = 'Terminal info not found: %s' % flight_id
self.code = 404 # Not found
class AirportNotFoundException(Exception):
def __init__(self, airport='', flight_num=''):
super(AirportNotFoundException, self).__init__()
self.message = 'Airport not found: %s for flight %s' % (airport, flight_num)
self.code = 404 # Not found
class FlightDurationUnknown(Exception):
def __init__(self, flight_id='', ete=''):
super(FlightDurationUnknown, self).__init__()
self.message = 'Unknown duration %s for flight %s' % (ete, flight_id)
self.code = 404 # Not found
class InvalidAlertCallbackException(Exception):
def __init__(self):
super(InvalidAlertCallbackException, self).__init__()
self.message = 'Invalid alert callback.'
self.code = 400 # Bad request
class OldFlightException(Exception):
def __init__(self, flight_number='', flight_id=''):
super(OldFlightException, self).__init__()
self.message = 'Old flight: %s %s' % (flight_number, flight_id)
self.code = 410 # Gone
class UnableToSetAlertException(Exception):
def __init__(self, reason=''):
super(UnableToSetAlertException, self).__init__()
self.message = 'Unable to set alert: %s' % reason
self.code = 403 # Gone
class UnableToSetEndpointException(Exception):
def __init__(self, endpoint=''):
super(UnableToSetEndpointException, self).__init__()
self.message = 'Unable to set endpoint: %s' % endpoint
self.code = 400 # Bad request
class UnableToGetAlertsException(Exception):
def __init__(self):
super(UnableToGetAlertsException, self).__init__()
self.message = 'Unable to get alerts from the datasource.'
self.code = 400 # Bad request
class UnableToDeleteAlertException(Exception):
def __init__(self, alert_id):
super(UnableToDeleteAlertException, self).__init__()
self.message = 'Unable to delete alert %s from the datasource.' % alert_id
self.code = 400 # Bad request
###############################################################################
# Model Exceptions
###############################################################################
class OrphanedFlightError(Exception):
def __init__(self, flight_id=''):
super(OrphanedFlightError, self).__init__()
self.message = 'Orphaned flight: %s' % flight_id
self.code = 500 # Server error
###############################################################################
# Driving Time Data Source Exceptions
###############################################################################
class DrivingTimeUnavailableError(Exception):
def __init__(self):
super(DrivingTimeUnavailableError, self).__init__()
self.message = 'Driving time is unavailable.'
self.code = 503 # Service unavailable
class BingMapsUnavailableError(DrivingTimeUnavailableError):
def __init__(self):
super(BingMapsUnavailableError, self).__init__()
self.message = 'Bing Maps API is unavailable.'
class GoogleDistanceAPIUnavailableError(DrivingTimeUnavailableError):
def __init__(self):
super(GoogleDistanceAPIUnavailableError, self).__init__()
self.message = 'Google distance API is unavailable.'
class MalformedDrivingDataException(Exception):
def __init__(self, orig_lat, orig_lon, dest_lat, dest_lon, data):
super(MalformedDrivingDataException, self).__init__()
self.message = "Can't get driving time (%f,%f) to (%f,%f): \n %s" % (
orig_lat, orig_lon, dest_lat, dest_lon, data)
self.code = 404 # Not found
class DrivingAPIQuotaException(Exception):
def __init__(self):
super(DrivingAPIQuotaException, self).__init__()
self.message = 'Exceeded driving API quota.'
self.code = 403 # Forbidden
class DrivingTimeUnauthorizedException(Exception):
def __init__(self):
super(DrivingTimeUnauthorizedException, self).__init__()
self.message = 'Driving time request unauthorized.'
self.code = 401 # Unauthorized
class NoDrivingRouteException(Exception):
def __init__(self, status_code, orig_lat, orig_lon, dest_lat, dest_lon):
super(NoDrivingRouteException, self).__init__()
self.message = "Can't get driving time (%f,%f) to (%f,%f)" % (
orig_lat, orig_lon, dest_lat, dest_lon)
self.code = status_code
###############################################################################
# Push Notification Exceptions
###############################################################################
class PushNotificationsUnavailableError(Exception):
def __init__(self):
super(PushNotificationsUnavailableError, self).__init__()
self.message = 'Push notifications are unavailable.'
self.code = 503 # Service unavailable
class UrbanAirshipUnavailableError(PushNotificationsUnavailableError):
def __init__(self):
super(UrbanAirshipUnavailableError, self).__init__()
self.message = 'Urban Airship is unavailable.'
class StackMobUnavailableError(PushNotificationsUnavailableError):
def __init__(self):
super(StackMobUnavailableError, self).__init__()
self.message = 'StackMob is unavailable.'
class PushNotificationsUnauthorizedError(Exception):
def __init__(self):
super(PushNotificationsUnauthorizedError, self).__init__()
self.message = 'Push notification unauthorized.'
self.code = 401 # Unauthorized
class UrbanAirshipUnauthorizedError(PushNotificationsUnauthorizedError):
def __init__(self):
super(UrbanAirshipUnauthorizedError, self).__init__()
self.message = 'Urban Airship request is unauthorized.'
class StackMobUnauthorizedError(PushNotificationsUnauthorizedError):
def __init__(self):
super(StackMobUnauthorizedError, self).__init__()
self.message = 'StackMob request is unauthorized.'
class PushNotificationsUnknownError(Exception):
def __init__(self, status_code=500, message=''):
super(PushNotificationsUnknownError, self).__init__()
self.message = message
self.code = status_code
class UrbanAirshipUnknownError(PushNotificationsUnknownError):
def __init__(self, status_code=500, message=''):
super(UrbanAirshipUnknownError, self).__init__(status_code, message)
class StackMobUnknownError(PushNotificationsUnknownError):
def __init__(self, status_code=500, message=''):
super(StackMobUnknownError, self).__init__(status_code, message)