Skip to content

Commit

Permalink
fixup! Remove url from example
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishrock123 committed Jun 22, 2020
1 parent 85d5bd0 commit a031ad3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ surf = { git = "https://github.com/Fishrock123/surf", branch = "deps-http-types-
serde = { version = "1.0.102", features = ["derive"] }
criterion = "0.3.1"
tempfile = "3.1.0"
url = "2.1.1"

[[test]]
name = "nested"
Expand Down
12 changes: 7 additions & 5 deletions examples/error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ async fn main() -> Result<()> {
tide::log::start();
let mut app = tide::new();

app.middleware(After(|mut res: Response| async move {
if let Some(err) = res.downcast_error::<url::ParseError>() {
app.middleware(After(|mut res: Response| async {
if let Some(err) = res.downcast_error::<tide::http::Error>() {
let msg = err.to_string().to_owned();
res.set_status(StatusCode::ImATeapot);
res.set_body(format!("Teapot Status: {}", msg));
}
Ok(res)
}));

app.at("/").get(|_req: Request<_>| async move {
let path = url::Url::parse("")?;
Ok(format!("Path is {}", path))
app.at("/").get(|_req: Request<_>| async {
if false {
return Ok("Good");
}
Err(tide::http::Error::from_str(StatusCode::BadRequest, "Uh oh"))
});

app.listen("127.0.0.1:8080").await?;
Expand Down

0 comments on commit a031ad3

Please sign in to comment.