Skip to content

🔖 Error Package v2#128

Open
dulciejackson wants to merge 17 commits intomasterfrom
feature/error-refactoring
Open

🔖 Error Package v2#128
dulciejackson wants to merge 17 commits intomasterfrom
feature/error-refactoring

Conversation

@dulciejackson
Copy link

@dulciejackson dulciejackson commented Nov 2, 2022

Error v2

Finally managed a refactor of the errors package! 🦞

Aims for v2 were to:

  • Improve transparency of mapping from error type to status code
  • Support all HTTP error codes
  • Improve documentation
  • Allow flexibility for custom context on project errors

Hence the new version, which:

** Demonstrates clear connection between ErrorTypes and status codes**

The new ErrorType enum maps names (e.g. Forbidden, TooManyRequests) to specific status codes. The enum values have a 1:1 mapping to status codes, reducing naming confusion and increasing transparency. A user can hover over an ErrorType value and immediately see the corresponding status code.

Includes all HTTP error codes by default

The ErrorType enum has been refactored to include every 4xx and 5xx HTTP status code - except "I'm a teapot" 🫖 .

** Provides improved documentation **

The OpenAPI comments have been improved, adding clarity to usage. Every status code in the ErrorType enum has a comment from the MDN docs clarifying its usage. The README has been updated with example usage for v2 and a migration guide.

** Allows flexibility for custom context **

Discussed with George, and identified a useful opportunity for projects to define a custom typing for the context property - so they can have a strictly typed structure if there's e.g. a specific error format they're looking to comply with. README and tests show how this can be used!

Copy link
Contributor

@georgeevans1995 georgeevans1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments, happy to discuss after lunch maybe?

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