Fix: Handle API errors returned as strings#64
Open
nicmendoza wants to merge 1 commit intopcorpet:mainfrom
Open
Fix: Handle API errors returned as strings#64nicmendoza wants to merge 1 commit intopcorpet:mainfrom
nicmendoza wants to merge 1 commit intopcorpet:mainfrom
Conversation
pcorpet
requested changes
Oct 4, 2024
Owner
pcorpet
left a comment
There was a problem hiding this comment.
Thanks a lot for sending a fix.
| error_type=error_json.get('type', str(response.status_code)), | ||
| message=error_json.get('message', json.dumps(response.json()))) | ||
| error_json = r.json().get('error', {}) | ||
| if isinstance(error_json, dict): |
Owner
There was a problem hiding this comment.
Weird indentation here, please dedent one tab.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per the documentation, the value for the "error" key in the API response to an error will typically be a dictionary , but may sometimes be a string, as shown here in the API documentation: https://airtable.com/developers/web/api/errors#anchor-404
Since this string-only response is not supported in airtable.py currently, this case will raise a somewhat opaque error. An example of the type of issue you will see was reported in issue #60.
This PR adds some branches in the logic to handle both expected cases, as well as a generalized and also a fallback.