Skip to content

Move router error handling into new middleware layer #3373

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

Merged
merged 5 commits into from
Mar 9, 2021

Conversation

jtgeibel
Copy link
Member

@jtgeibel jtgeibel commented Mar 7, 2021

This moves handling of routing errors into middleware and adds a test for the conversion.

Additionally we previously called router.recognize() instead of router.call(). By switching we can let the conduit-router logic handle adding Params to the request extensions.

A potential allocation is removed from json error handling, although the compiler may be able to eliminate that allocation already.

r? @Turbo87

jtgeibel added 5 commits March 6, 2021 23:36
The outer R404 will catch any routing errors, so it is unnecessary here.
Other error conversions in `AppError::try_convert()` cannot be moved
because endpoint logic relys on being able to detect these (converted)
errors. Errors that endpoints don't care about (or cannot detect), can
be converted to user-friendly errors in middleware.
Copy link
Member

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

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

LGTM

one small comment, but feel free to r=me

src/router.rs Outdated
body,
Body::Owned(vec) if vec == br#"{"errors":[{"detail":"Not Found"}]}"#
));
}
Copy link
Member

Choose a reason for hiding this comment

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

would it make sense to convert that to a more high-level API test?

Copy link
Member Author

Choose a reason for hiding this comment

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

This particular test moved to the middleware. We could do something under tests/all.rs as well. The main difference would be that it would load other middleware layers as well.

@jtgeibel
Copy link
Member Author

jtgeibel commented Mar 9, 2021

@bors r=Turbo87

@bors
Copy link
Contributor

bors commented Mar 9, 2021

📌 Commit ff1f7cc has been approved by Turbo87

@bors
Copy link
Contributor

bors commented Mar 9, 2021

⌛ Testing commit ff1f7cc with merge 03666dd...

@bors
Copy link
Contributor

bors commented Mar 9, 2021

☀️ Test successful - checks-actions
Approved by: Turbo87
Pushing 03666dd to master...

@bors bors merged commit 03666dd into rust-lang:master Mar 9, 2021
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.

4 participants