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

feat: improve error serialization #111

Merged
merged 2 commits into from
Jul 2, 2020

Conversation

john-goldsmith
Copy link
Contributor

Improves the serialization of errors to be compliant with the JSON:API
spec:

  • Remove explicit check for Error instances and, instead, validate
    both instances of Error and POJOs using validateError
  • Restrict links object properties to about
  • Restrict links.about object property type to string
  • Restrict source object properties to pointer and parameter
  • Restrict meta object property type to object
  • Add function for validating status against a list of known HTTP
    status codes
  • Restrict status object property type to number
  • Add tests for new functionality
  • Update tests for changed functionality
  • Update README.md with additional usage examples

Addresses issue #110

@john-goldsmith john-goldsmith changed the title feat: improve error serialization (#110) feat: improve error serialization Jul 1, 2020
@coveralls
Copy link

coveralls commented Jul 1, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling b4876fb on john-goldsmith:improved-error-serialization into 4ddf2d8 on danivek:master.

@danivek danivek self-requested a review July 1, 2020 06:08
@danivek danivek linked an issue Jul 1, 2020 that may be closed by this pull request
README.md Outdated Show resolved Hide resolved
lib/validator.js Outdated Show resolved Hide resolved
lib/validator.js Outdated Show resolved Hide resolved
Improves the serialization of errors to be compliant with the JSON:API
spec:

* Remove explicit check for `Error` instances and, instead, validate
  both instances of `Error` and POJOs using `validateError`
* Restrict `links` object properties to `about`
* Restrict `links.about` object property type to string
* Restrict `source` object properties to `pointer` and `parameter`
* Restrict `meta` object property type to object
* Add function for validating `status` against a list of known HTTP
  status codes
* Restrict `status` object property type to number
* Add tests for new functionality
* Update tests for changed functionality
* Update README.md with additional usage examples
Improves the serialization of errors:

* Update `title` to use the constructor name only if it's not 'Object'
* Support both `status` and `statusCode` properties
* Update JSDoc blocks to include more information
* Fix `status` typo in `README.md`
* Update `README.md` to indicate support for both `status` and
  `statusCode`
@john-goldsmith john-goldsmith force-pushed the improved-error-serialization branch from 1ce8a70 to b4876fb Compare July 1, 2020 19:33
@danivek danivek merged commit 7aafe29 into danivek:master Jul 2, 2020
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.

Error instance serialization missing properties
3 participants