Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON codec wrapper to handle exceptions #791

Merged
merged 3 commits into from
Sep 7, 2020
Merged

JSON codec wrapper to handle exceptions #791

merged 3 commits into from
Sep 7, 2020

Conversation

kstenerud
Copy link
Contributor

Goal

NSJSONSerialization can sometimes throw an exception, even though the API has an NSError field. We should have a unified way to handle JSON without having to remember to put in try/catch blocks, or manually go through our data to ensure it conforms before attempting to encode, or worry about bad data causing the decoder to freak out.

Design

BSGJSONSerialization wraps all NSJSONSerialization calls in a try/catch block, turning any resulting exceptions into an NSError.

Changeset

  • Added BSGJSONSerialization
  • Updated instances of NSJSONSerialization to use BSGJSONSerialization instead.

Testing

  • Added tests for all components that (de)serialize JSON to ensure they work as expected.

@kstenerud kstenerud requested a review from kattrali September 4, 2020 09:46
@kstenerud kstenerud changed the base branch from master to next September 4, 2020 09:48
NSJSONSerialization can sometimes throw an exception, even though the API has an NSError field. BSGJSONSerialization wraps all NSJSONSerialization calls in a try/catch block, turning any resulting exceptions into an NSError.

This gives us a more robust way to handle JSON in a unified manner, as opposed to having to remember to put try/catch around every (de)serialization, or check all dictionaries manually for valid data.
@kstenerud kstenerud merged commit 20ac128 into next Sep 7, 2020
@nickdowell nickdowell deleted the json-guards branch January 12, 2021 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants