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

Error handler with context #158

Merged
merged 2 commits into from
Oct 11, 2018
Merged

Conversation

frenzzy
Copy link
Member

@frenzzy frenzzy commented Oct 5, 2018

The router no longer mutate errors to avoid issues with non-extensible objects.
If your code relies on error.context or error.code you still can access the same variables using errorHandler option:

errorHandler(error, context) {
  const code = error.status || 500
  console.log(error, context, code)
}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Closes #152
Closes #154
Closes #156

@codecov-io
Copy link

codecov-io commented Oct 5, 2018

Codecov Report

Merging #158 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #158   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines         147    144    -3     
  Branches       44     42    -2     
=====================================
- Hits          147    144    -3
Impacted Files Coverage Δ
src/UniversalRouter.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5f7dbf...b61f561. Read the comment docs.

@frenzzy frenzzy mentioned this pull request Oct 5, 2018
@frenzzy frenzzy force-pushed the error-handler-context branch from 9ef198e to 1f50f29 Compare October 5, 2018 15:19
CHANGELOG.md Outdated
- If your code relies on `error.context` or `error.code` you still can access the same variables using `errorHandler` option:
```js
errorHandler(error, context) {
const code = error.message === 'Route not found' ? 404 : 500
Copy link

Choose a reason for hiding this comment

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

Checking the message string feels dirty. How about a 3rd arg for the code?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is better to use a special route with (.*) path for not found errors. This example just shows how easy to reach a backward compatibility. Maybe need to mention it, what do you think?

Copy link

Choose a reason for hiding this comment

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

Agree on the special route and would put that in the docs. I wouldn't encourage the string check and explicitly mention it's for backwards compat.

@frenzzy frenzzy force-pushed the error-handler-context branch from ff9f268 to a7757c4 Compare October 10, 2018 19:00
@frenzzy frenzzy force-pushed the error-handler-context branch from a7757c4 to b61f561 Compare October 10, 2018 19:16
@frenzzy frenzzy merged commit 04ffb79 into kriasoft:master Oct 11, 2018
@frenzzy frenzzy deleted the error-handler-context branch October 11, 2018 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants