1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::{convert::Infallible, sync::Arc};

use serde::{Deserialize, Serialize};

use crate::document::ApiDocument;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct ApiErrorItem {
    // http状态
    pub status: u16,

    // 错误标识
    pub code: String,

    // 错误原因
    pub cause: String,
}

pub trait ApiErrors {
    fn api_errors() -> Vec<ApiErrorItem>;
}

impl ApiErrors for Infallible {
    fn api_errors() -> Vec<ApiErrorItem> {
        vec![]
    }
}

impl<T: ApiErrors> ApiErrors for Arc<T> {
    fn api_errors() -> Vec<ApiErrorItem> {
        T::api_errors()
    }
}

impl ApiErrors for ApiDocument {
    fn api_errors() -> Vec<ApiErrorItem> {
        vec![]
    }
}