This repository was archived by the owner on Jan 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patherror.py
More file actions
108 lines (90 loc) · 3.5 KB
/
error.py
File metadata and controls
108 lines (90 loc) · 3.5 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
"""
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
"""
from __future__ import unicode_literals
class GraphError(Exception):
def __init__(self, prop_dict, status_code):
"""Initialize a GraphError given the JSON
error response dictionary, and the HTTP status code
Args:
prop_dict (dict): A dictionary containing the response
from Graph
status_code (int): The HTTP status code (ex. 200, 201, etc.)
"""
if "code" not in prop_dict or "message" not in prop_dict:
prop_dict["code"] = ErrorCode.Malformed.value
prop_dict["message"] = "The received response was malformed"
super(GraphError, self).__init__(prop_dict["code"] + " - " + prop_dict["message"])
else:
super(GraphError, self).__init__(prop_dict["code"] + " - " + prop_dict["message"])
self._prop_dict = prop_dict
self._status_code = status_code
@property
def status_code(self):
"""The HTTP status code
Returns:
int: The HTTP status code
"""
return self._status_code
@property
def code(self):
"""The Graph error code sent back in
the response. Possible codes can be found
in the :class:`ErrorCode` enum.
Returns:
str: The error code
"""
return self._prop_dict["code"]
@property
def inner_error(self):
"""Creates a GraphError object from the specified inner
error within the response.
Returns:
:class:`GraphError`: Error from within the inner
response
"""
return GraphError(self._prop_dict["innererror"], self.status_code) if "innererror" in self._prop_dict else None
def matches(self, code):
"""Recursively searches the :class:`GraphError` to find
if the specified code was found
Args:
code (str): The error code to search for
Returns:
bool: True if the error code was found, false otherwise
"""
if self.code == code:
return True
return False if self.inner_error is None else self.inner_error.matches(code)
class ErrorCode(object):
#: Access was denied to the resource
AccessDenied = "accessDenied"
#: The activity limit has been reached
ActivityLimitReached = "activityLimitReached"
#: A general exception occured
GeneralException = "generalException"
#: An invalid range was provided
InvalidRange = "invalidRange"
#: An invalid request was provided
InvalidRequest = "invalidRequest"
#: The requested resource was not found
ItemNotFound = "itemNotFound"
#: Malware was detected in the resource
MalwareDetected = "malwareDetected"
#: The name already exists
NameAlreadyExists = "nameAlreadyExists"
#: The action was not allowed
NotAllowed = "notAllowed"
#: The action was not supported
NotSupported = "notSupported"
#: The resource was modified
ResourceModified = "resourceModified"
#: A resync is required
ResyncRequired = "resyncRequired"
#: The Graph service is not available
ServiceNotAvailable = "serviceNotAvailable"
#: The quota for this OneDrive has been reached
QuotaLimitReached = "quotaLimitReached"
#: The user is unauthenticated
Unauthenticated = "unauthenticated"
#: The response was malformed
Malformed = "malformed"