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
17
18
use http::StatusCode;
use svc_authz::error::{Error, IntentError, Kind};

use crate::Error as TheError;

impl From<Error> for TheError {
    fn from(value: Error) -> TheError {
        let fun = |status: StatusCode, inner: &IntentError| -> TheError {
            let mut err = TheError::from(status);
            err.set_detail(&inner.to_string());
            err
        };
        match value.kind() {
            Kind::Forbidden(ref inner) => fun(StatusCode::FORBIDDEN, inner),
            Kind::Network(ref inner) => fun(StatusCode::FAILED_DEPENDENCY, inner),
        }
    }
}