1 unstable release

0.1.0 Dec 7, 2024

#1 in #status-code

Download history 120/week @ 2024-12-04 21/week @ 2024-12-11 1/week @ 2024-12-18

142 downloads per month

MIT license

8KB
186 lines

Errors for conveniently attaching status codes to error cases.

use api_err::{CategoryExt, Context};

fn add_one(request: &str) -> api_err::Result<String> {
   let input = request.parse::<i64>().bad_request()?;
   let output = input.checked_add(1).context("Input too large").bad_request()?;
   Ok(output.to_string())
}

Errors without a category attached default to the "Internal Server"-like error.

Dependencies

~135KB