forked from geduldig/TwitterAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwitterError.py
More file actions
38 lines (24 loc) · 931 Bytes
/
TwitterError.py
File metadata and controls
38 lines (24 loc) · 931 Bytes
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
__author__ = "geduldig"
__date__ = "November 30, 2014"
__license__ = "MIT"
import logging
class TwitterError(Exception):
"""Base class for Twitter exceptions"""
pass
class TwitterConnectionError(TwitterError):
"""Raised when the connection needs to be re-established"""
def __init__(self, value):
super(Exception, self).__init__(value)
logging.warning('%s %s' % (type(value), value))
class TwitterRequestError(TwitterError):
"""Raised when request fails"""
def __init__(self, status_code):
if status_code >= 500:
msg = 'Twitter internal error (you may re-try)'
else:
msg = 'Twitter request failed'
logging.info('Status code %d: %s' % (status_code, msg))
super(Exception, self).__init__(msg)
self.status_code = status_code
def __str__(self):
return '%s (%d)' % (self.args[0], self.status_code)