api-err 0.1.0

Convenient to write errors for APIs
Documentation
  • Coverage
  • 100%
    17 out of 17 items documented1 out of 8 items with examples
  • Size
  • Source code size: 7.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.82 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • shelbyd/api-err
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • shelbyd

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.