I've been thinking of ways to improve the error handling story in tide, related to #138, and one of the things that came up is that tide::EndpointResult is quite inconvenient to type.
I'd like to propose we rename this to tide::Result instead, and document that it's intended for use in endpoints. We can then provide examples of the Into conversions on the Result type too, which should help with documenting what valid responses are.
async fn new_message(mut cx: Context<Database>) -> tide::Result<String> {
let msg = cx.body_json().await.client_err()?;
Ok(cx.state().insert(msg).to_string())
}
use tide::EndpointResult;
async fn new_message(mut cx: Context<Database>) -> EndpointResult<String> {
let msg = cx.body_json().await.client_err()?;
Ok(cx.state().insert(msg).to_string())
}
PR #258 moves EndpointResult into endpoint, which should make it a little more natural. Meanwhile, I think it's more relevant to move this into tide::Result _when_ this type can cover a larger ground than just endpoints - possibly be more consistent around middlewares as well. (as in, Middleware today return a future of Response -- if it returns a future of this proposed Result too, then I think it's scope expands into a larger a tide::Result). But that's a larger discussion that requires error handling to be nailed out first to know that the Error type of this Result is going to be. Currently in today's state, I think it's only relevant to endpoints only.
@yoshuawuyts I think this can be closed as it has been renamed in https://github.com/http-rs/tide/commit/5a2bbd5b23c5ea71bd76ce8b85a651b516372832?
Most helpful comment
PR #258 moves
EndpointResultintoendpoint, which should make it a little more natural. Meanwhile, I think it's more relevant to move this intotide::Result_when_ this type can cover a larger ground than just endpoints - possibly be more consistent around middlewares as well. (as in, Middleware today return a future ofResponse-- if it returns a future of this proposedResulttoo, then I think it's scope expands into a larger atide::Result). But that's a larger discussion that requires error handling to be nailed out first to know that the Error type of this Result is going to be. Currently in today's state, I think it's only relevant to endpoints only.