-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patherrors.py
More file actions
105 lines (76 loc) · 3.11 KB
/
errors.py
File metadata and controls
105 lines (76 loc) · 3.11 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
# -*- coding: utf-8 -*-
"""All Trakt related errors that are worth processing. Note that 412 response
codes are ignored because the only requests that this library sends out are
guaranteed to have the application/json MIME type set.
"""
__author__ = 'Jon Nappi'
__all__ = [
'TraktException',
'BadRequestException',
'OAuthException',
'ForbiddenException',
'NotFoundException',
'MethodNotAllowedException',
'ConflictException',
'ProcessException',
'LockedUserAccountException',
'RateLimitException',
'TraktInternalException',
'TraktGatewayUnavailable',
'TraktUnavailable',
]
class TraktException(Exception):
"""Base Exception type for trakt module"""
http_code = message = None
def __init__(self, response=None):
self.response = response
def __str__(self):
return self.message
class BadRequestException(TraktException):
"""TraktException type to be raised when a 400 return code is received"""
http_code = 400
message = "Bad Request - request couldn't be parsed"
class OAuthException(TraktException):
"""TraktException type to be raised when a 401 return code is received"""
http_code = 401
message = 'Unauthorized - OAuth must be provided'
class ForbiddenException(TraktException):
"""TraktException type to be raised when a 403 return code is received"""
http_code = 403
message = 'Forbidden - invalid API key or unapproved app'
class NotFoundException(TraktException):
"""TraktException type to be raised when a 404 return code is received"""
http_code = 404
message = 'Not Found - method exists, but no record found'
class MethodNotAllowedException(TraktException):
"""TraktException type to be raised when a 405 return code is received"""
http_code = 405
message = 'Method not Allowed'
class ConflictException(TraktException):
"""TraktException type to be raised when a 409 return code is received"""
http_code = 409
message = 'Conflict - resource already created'
class ProcessException(TraktException):
"""TraktException type to be raised when a 422 return code is received"""
http_code = 422
message = 'Unprocessable Entity - validation errors'
class LockedUserAccountException(TraktException):
"""TraktException type to be raised when a 423 return code is received"""
http_code = 423
message = 'Locked User Account - have the user contact support'
class RateLimitException(TraktException):
"""TraktException type to be raised when a 429 return code is received"""
http_code = 429
message = 'Rate Limit Exceeded'
class TraktInternalException(TraktException):
"""TraktException type to be raised when a 500 error is raised"""
http_code = 500
message = 'Internal Server Error'
class TraktGatewayUnavailable(TraktException):
"""TraktException type to be raised when a 502 error is raised"""
http_code = 502
message = 'Trakt Unavailable - Bad Gateway'
class TraktUnavailable(TraktException):
"""TraktException type to be raised when a 503 error is raised"""
http_code = 503
message = 'Trakt Unavailable - server overloaded'