thruster-rs / Thruster

A fast, middleware based, web framework written in Rust
MIT License
1.06k stars 47 forks source link

Incorrect ThrusterError struct definition in error handling docs #247

Closed Tronikelis closed 1 year ago

Tronikelis commented 1 year ago

Hey, the docs define a status property which does not exist in the latest version 1.3.1, did not check older

Docs:

#[middleware_fn]
async fn error(mut context: Ctx, _next: MiddlewareNext<Ctx>) -> MiddlewareResult<Ctx> {
    let res = "Hello, world".parse::<u32>();
    let non_existent_param = map_try!(res, Err(_) => {
        Error {
          context,
          message: "Parsing failure!".to_string(),
          status: 400 // <- here !
        }
      }
    );

    context.body(&format!("{}", non_existent_param));

    Ok(context)
}

status does not exist in the struct:

https://github.com/thruster-rs/Thruster/blob/2a454e1958687aa67946781251fa70c49f029cf3/thruster/src/core/errors.rs#L4-L8

trezm commented 1 year ago

Ah, good call, it was redundant and confusing because it really should be set on the context object instead. I'll update the docs accordingly.

Thank you!