Improve GraphQL error handling
This commit is contained in:
@@ -1735,6 +1735,7 @@ class Client(object):
|
|||||||
}
|
}
|
||||||
data = {"doc_id": 1491398900900362, "variables": json.dumps({"data": data})}
|
data = {"doc_id": 1491398900900362, "variables": json.dumps({"data": data})}
|
||||||
j = self._payload_post("/webgraphql/mutation", data)
|
j = self._payload_post("/webgraphql/mutation", data)
|
||||||
|
handle_graphql_errors(j)
|
||||||
|
|
||||||
def createPlan(self, plan, thread_id=None):
|
def createPlan(self, plan, thread_id=None):
|
||||||
"""
|
"""
|
||||||
|
@@ -51,7 +51,7 @@ def graphql_response_to_json(content):
|
|||||||
continue
|
continue
|
||||||
_util.handle_payload_error(x)
|
_util.handle_payload_error(x)
|
||||||
[(key, value)] = x.items()
|
[(key, value)] = x.items()
|
||||||
_util.handle_graphql_error(value)
|
_util.handle_graphql_errors(value)
|
||||||
if "response" in value:
|
if "response" in value:
|
||||||
rtn[int(key[1:])] = value["response"]
|
rtn[int(key[1:])] = value["response"]
|
||||||
else:
|
else:
|
||||||
|
@@ -144,14 +144,21 @@ def handle_payload_error(j):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def handle_graphql_error(j):
|
def handle_graphql_errors(j):
|
||||||
if j.get("error") and "debug_info" in j["error"] and "code" in j["error"]:
|
errors = []
|
||||||
|
if "error" in j:
|
||||||
|
errors = [j["error"]]
|
||||||
|
if "errors" in j:
|
||||||
|
errors = j["errors"]
|
||||||
|
if errors:
|
||||||
|
error = errors[0] # TODO: Handle multiple errors
|
||||||
|
# TODO: Use `summary`, `severity` and `description`
|
||||||
raise FBchatFacebookError(
|
raise FBchatFacebookError(
|
||||||
"Error #{} when sending request: {!r}".format(
|
"GraphQL error #{}: {} / {!r}".format(
|
||||||
j["error"]["code"], j["error"]["debug_info"]
|
error.get("code"), error.get("message"), error.get("debug_info")
|
||||||
),
|
),
|
||||||
fb_error_code=j["error"]["code"],
|
fb_error_code=error.get("code"),
|
||||||
fb_error_message=j["error"]["debug_info"],
|
fb_error_message=error.get("message"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user