Skip to content

Commit 16955ac

Browse files
author
Evan Chen
committed
Minor improvements to error messages
Summary: - Improved error message for non instantiated API calls. - Added formatting and prettified error calls. Test Plan: 1. Try and instantiate an object without instantiating FacebookAdsApi object 2. Try making a broken API call
1 parent 39120d7 commit 16955ac

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

facebookads/exceptions.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"""
2525

2626
import json
27+
import re
2728

2829

2930
class FacebookError(Exception):
@@ -85,14 +86,18 @@ def __init__(
8586
del request['files']
8687

8788
super(FacebookRequestError, self).__init__(
88-
"%s \n" % self._message +
89-
"Request:\n\t%s\n" % request +
90-
"Response:\n" +
91-
"\tHTTP Status: %s\n\tHeaders:%s\n\tBody: %s\n" % (
92-
self._http_status,
93-
self._http_headers,
94-
body,
95-
)
89+
"\n\n" +
90+
" Message: %s\n" % self._message +
91+
" Method: %s\n" % request['method'] +
92+
" Path: %s\n" % request['path'] +
93+
" Params: %s\n" % request['params'] +
94+
"\n" +
95+
" Status: %s\n" % self._http_status +
96+
" Response:\n %s" % re.sub(
97+
r"\n", "\n ",
98+
json.dumps(self._body, indent=2)
99+
) +
100+
"\n"
96101
)
97102

98103
def request_context(self):

facebookads/objects.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ def get_api_assured(self):
405405
api = self.get_api()
406406
if not api:
407407
raise FacebookBadObjectError(
408-
"%s does not yet have an associated api object."
408+
"%s does not yet have an associated api object.\n"
409+
"Did you forget to instantiate an API session with: "
410+
"FacebookAdsApi.init(app_id, app_secret, access_token)"
409411
% self.__class__.__name__
410412
)
411413

0 commit comments

Comments
 (0)