Skip to content

Commit

Permalink
remove Into<Result>, use ok-wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Jun 27, 2020
1 parent 1dfa868 commit f03ca44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ async fn handle_graphql(mut request: Request<State>) -> tide::Result {
StatusCode::BadRequest
};

Response::builder(status)
Ok(Response::builder(status)
.body(Body::from_json(&response)?)
.into()
.build())
}

async fn handle_graphiql(_: Request<State>) -> tide::Result<impl Into<Response>> {
Expand Down
13 changes: 8 additions & 5 deletions examples/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,22 @@ async fn main() -> Result<()> {

app.middleware(After(|result: Result| async move {
let response = result.unwrap_or_else(|e| Response::new(e.status()));
match response.status() {

let response = match response.status() {
StatusCode::NotFound => Response::builder(404)
.content_type(mime::HTML)
.body(NOT_FOUND_HTML_PAGE)
.into(),
.build(),

StatusCode::InternalServerError => Response::builder(500)
.content_type(mime::HTML)
.body(INTERNAL_SERVER_ERROR_HTML_PAGE)
.into(),
.build(),

_ => Ok(response),
}
_ => response,
};

Ok(response)
}));

app.middleware(user_loader);
Expand Down
6 changes: 0 additions & 6 deletions src/response_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,3 @@ impl Into<Response> for ResponseBuilder {
self.build()
}
}

impl Into<crate::Result> for ResponseBuilder {
fn into(self) -> crate::Result {
Ok(self.build())
}
}

0 comments on commit f03ca44

Please sign in to comment.