forked from sns-sdks/python-facebook
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexceptions.py
More file actions
48 lines (34 loc) · 1.16 KB
/
exceptions.py
File metadata and controls
48 lines (34 loc) · 1.16 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
"""
Exceptions for library
"""
class PyFacebookException(Exception):
"""Base class for exceptions in this module."""
pass
class LibraryError(PyFacebookException):
"""
A class for library error template.
"""
def __init__(self, kwargs: dict):
self.code = -1 # error code in library inside
self.message = "exception in library"
for key, value in kwargs.items():
setattr(self, key, value)
def __repr__(self):
msg = ",".join(
[f"{k}={v}" for k, v in self.__dict__.items() if not k.startswith("_")]
)
return f"{self.__class__.__name__}({msg})"
def __str__(self):
return self.__repr__()
class FacebookError(LibraryError):
"""
A class representing facebook error response
Refer: https://developers.facebook.com/docs/graph-api/using-graph-api/error-handling
Common fields are: message,code,error_subcode,error_user_msg,error_user_title,fbtrace_id
"""
def __init__(self, kwargs: dict):
self._data = kwargs
error = kwargs["error"]
super().__init__(kwargs=error)
class PyFacebookDeprecationWaring(DeprecationWarning):
pass