Skip to content

Possible regression when query method fails #656

@xorxsan

Description

@xorxsan

In tide version 0.9.0 when a request failed because query() could not parse the query string parameters, it throwed a 400 error with additional information.

Current Behavior

When query() cannot parse the querystring parameters it only throws a 400 Bad Request error without any additional information:

>
< HTTP/1.1 400 Bad Request
< content-length: 0
< date: Tue, 21 Jul 2020 17:03:39 GMT
<
* Connection #0 to host localhost left intact

Code/Gist

#[derive(serde::Deserialize)]
struct FailingParams {
    requestor: String,
    selections: std::collections::HashMap<String, String>,
    quantities: Vec<i32>,
}

async fn handle_endpoint(req: tide::Request<()>) -> tide::Result {
    let queries: FailingParams = req.query()?;
    let mut res = tide::Response::new(tide::StatusCode::Ok);
    res.set_body("ok");
    Ok(res)
}

#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
    let mut address = String::from("127.0.0.1:");
    address.push_str("5000");

    let mut app = tide::new();
    app.at("/").get(|_| async { Ok("Healthy") });
    app.at("/v1/endpoint").get(handle_endpoint);
    app.listen(address).await?;
    Ok(())
}

Expected behavior/code

Same behaviour as version 0.9.0:
curl "http://localhost:5000/v1/endpoint?requestor=test":

< HTTP/1.1 400 Bad Request
< content-length: 42
< date: Tue, 21 Jul 2020 18:00:01 GMT
< content-type: text/plain;charset=utf-8
<
failed with reason: missing field `selections`* Connection #0 to host localhost left intact

Environment

  • Rust toolchain version(s): stable-x86_64-pc-windows-gnu
  • OS: Windows 10

Possible Solution

Add error message like in tide's version 0.9.0

Additional context/Screenshots

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions