Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible regression when query method fails #656

Closed
xorxsan opened this issue Jul 21, 2020 · 2 comments
Closed

Possible regression when query method fails #656

xorxsan opened this issue Jul 21, 2020 · 2 comments

Comments

@xorxsan
Copy link

xorxsan commented Jul 21, 2020

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

@Fishrock123
Copy link
Member

Right, Tide no longer sends error messages in bodies by default as of f4ef3bb.

I recommend starting up a logger, such as tide's built in one, so that you can get these messages from tide's presently-on-by-default logging middleware.

#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
    tide::log::start();
    // ...
}

Fishrock123 added a commit to Fishrock123/tide that referenced this issue Jul 21, 2020
Fishrock123 added a commit to Fishrock123/tide that referenced this issue Jul 21, 2020
@xorxsan
Copy link
Author

xorxsan commented Jul 21, 2020

Hi @Fishrock123
thanks for your quick response. I just added tide::log::start(); as you suggested and I'm getting some information. I'll add more logging in the controllers. I close this ticket.

@xorxsan xorxsan closed this as completed Jul 21, 2020
jbr pushed a commit that referenced this issue Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants