forked from vimeo/vimeo.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exceptions.py
97 lines (61 loc) · 2.64 KB
/
exceptions.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
#!/usr/bin/env python
class BaseVimeoException(Exception):
def _get_message(self, response):
json = None
try:
json = response.json()
except:
pass
if json:
message = json.get('error') or json.get('Description')
else:
message = response.text
return message
def __init__(self, response, message):
# API error message
self.message = self._get_message(response)
# HTTP status code
self.status_code = response.status_code
super(BaseVimeoException, self).__init__(self.message)
class ObjectLoadFailure(Exception):
def __init__(self, message):
super(ObjectLoadFailure, self).__init__(message)
class UploadTicketCreationFailure(BaseVimeoException):
def __init__(self, response, message):
super(UploadTicketCreationFailure, self).__init__(response, message)
class VideoCreationFailure(BaseVimeoException):
def __init__(self, response, message):
super(VideoCreationFailure, self).__init__(response, message)
class VideoUploadFailure(BaseVimeoException):
def __init__(self, response, message):
super(VideoUploadFailure, self).__init__(response, message)
class PictureCreationFailure(BaseVimeoException):
def __init__(self, response, message):
super(PictureCreationFailure, self).__init__(response, message)
class PictureUploadFailure(BaseVimeoException):
def __init__(self, response, message):
super(PictureUploadFailure, self).__init__(response, message)
class PictureActivationFailure(BaseVimeoException):
def __init__(self, response, message):
super(PictureActivationFailure, self).__init__(response, message)
class TexttrackCreationFailure(BaseVimeoException):
def __init__(self, response, message):
super(TexttrackCreationFailure, self).__init__(response, message)
class TexttrackUploadFailure(BaseVimeoException):
def __init__(self, response, message):
super(TexttrackUploadFailure, self).__init__(response, message)
class APIRateLimitExceededFailure(BaseVimeoException):
def _get_message(self, response):
guidelines = 'https://developer.vimeo.com/guidelines/rate-limiting'
message = super(APIRateLimitExceededFailure, self)._get_message(
response
)
limit_reset_time = response.headers.get('x-ratelimit-reset')
if limit_reset_time:
text = '{} \n limit will reset on: {}.\n About this limit: {}'
message = text.format(
message,
limit_reset_time,
guidelines
)
return message