svc-error 0.1.1

An implementation of RFC7807: Problem Details for HTTP APIs.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use diesel::result::Error;
use http::StatusCode;

use crate::Error as TheError;

impl From<Error> for TheError {
    fn from(value: Error) -> TheError {
        let status = match &value {
            Error::NotFound => StatusCode::NOT_FOUND,
            _ => StatusCode::UNPROCESSABLE_ENTITY,
        };
        let mut err = TheError::from(status);
        err.set_detail(&format!("a database error = '{}'", &value));
        err
    }
}