autoendpoint/routers/stub/
error.rs1use crate::error::ApiErrorKind;
2use crate::routers::RouterError;
3use actix_web::http::StatusCode;
4
5#[derive(thiserror::Error, Clone, Debug)]
7pub enum StubError {
8 #[error("Failed to decode the credential settings")]
9 Credential,
10
11 #[error("Invalid JSON response from Test")]
12 InvalidResponse,
13
14 #[error("General error")]
15 General(String),
16
17 #[error("Missing User error")]
18 Missing,
19}
20
21impl StubError {
22 pub fn status(&self) -> StatusCode {
24 match self {
25 StubError::Missing => StatusCode::GONE,
26
27 StubError::Credential | StubError::General(_) => StatusCode::INTERNAL_SERVER_ERROR,
28
29 StubError::InvalidResponse => StatusCode::BAD_GATEWAY,
30 }
31 }
32
33 pub fn errno(&self) -> Option<usize> {
35 match self {
36 StubError::Missing => Some(106),
37
38 _ => None,
39 }
40 }
41
42 pub fn extras(&self) -> Vec<(&str, String)> {
43 match self {
44 StubError::General(status) => {
45 vec![("status", status.to_string())]
46 }
47 _ => vec![],
48 }
49 }
50}
51
52impl From<StubError> for ApiErrorKind {
53 fn from(e: StubError) -> Self {
54 ApiErrorKind::Router(RouterError::Stub(e))
55 }
56}