Add error handling to Request methods#308
Open
brightly-salty wants to merge 3 commits intohttp-rs:mainfrom
Open
Add error handling to Request methods#308brightly-salty wants to merge 3 commits intohttp-rs:mainfrom
brightly-salty wants to merge 3 commits intohttp-rs:mainfrom
Conversation
Make all associated Request methods return a Result<Self, Error> instead of Self and panicking. Change docs and doc-tests to reflect this, and remove manual parsing in doc-tests and unit tests
yoshuawuyts
requested changes
Dec 24, 2020
Member
yoshuawuyts
left a comment
There was a problem hiding this comment.
Few nits, but overall this is a really promising PR. Thank you!
| U::Error: std::fmt::Debug + Into<anyhow::Error>, | ||
| { | ||
| let url = url.try_into().expect("Could not convert into a valid url"); | ||
| let url = url.try_into().map_err(|e| Error::new(500, e))?; |
Member
There was a problem hiding this comment.
This does not need the map_err call to work:
Suggested change
| let url = url.try_into().map_err(|e| Error::new(500, e))?; | |
| let url = url.try_into()?; |
But if it's for clarity purposes, it's preferable to use the Status trait instead:
Suggested change
| let url = url.try_into().map_err(|e| Error::new(500, e))?; | |
| let url = url.try_into().status(500)?; |
Contributor
Author
There was a problem hiding this comment.
I got the following error after replacing map_err with status
no method named `status` found for enum `std::result::Result<url::Url, <U as std::convert::TryInto<url::Url>>::Error>` in the current scope
method not found in `std::result::Result<url::Url, <U as std::convert::TryInto<url::Url>>::Error>`
note: the method `status` exists but the following trait bounds were not satisfied:
`<U as std::convert::TryInto<url::Url>>::Error: std::error::Error`
which is required by `std::result::Result<url::Url, <U as std::convert::TryInto<url::Url>>::Error>: status::Status<url::Url, <U as std::convert::TryInto<url::Url>>::Error>`
`<U as std::convert::TryInto<url::Url>>::Error: std::marker::Send`
which is required by `std::result::Result<url::Url, <U as std::convert::TryInto<url::Url>>::Error>: status::Status<url::Url, <U as std::convert::TryInto<url::Url>>::Error>`
`<U as std::convert::TryInto<url::Url>>::Error: std::marker::Sync`
which is required by `std::result::Result<url::Url, <U as std::convert::TryInto<url::Url>>::Error>: status::Status<url::Url, <U as std::convert::TryInto<url::Url>>::Error>`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make all associated Request methods return a Result<Self, Error> instead of Self and panicking.
Change docs and doc-tests to reflect this, and remove manual parsing in doc-tests and unit tests
Fixes #303