Tide: Rename EndpointResult to Result

Created on 19 May 2019  路  2Comments  路  Source: http-rs/tide

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.

Proposed

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())
}

Current

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())
}
feature

Most helpful comment

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.

All 2 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gruberb picture gruberb  路  4Comments

AsceticBear picture AsceticBear  路  5Comments

kamyuentse picture kamyuentse  路  4Comments

Nemo157 picture Nemo157  路  6Comments

jbr picture jbr  路  4Comments