line_login_api/
error.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone)]
4pub enum LineLoginError {
5    ApiError(LineApiError),
6    HttpError(LineHttpError),
7    SystemError(LineSystemError),
8}
9
10impl LineLoginError {
11    pub fn status(&self) -> u16 {
12        match self {
13            LineLoginError::ApiError(e) => e.status,
14            LineLoginError::HttpError(e) => e.status,
15            LineLoginError::SystemError(_) => 0,
16        }
17    }
18    pub fn api_error(&self) -> Option<&LineApiErrorResponse> {
19        match self {
20            LineLoginError::ApiError(e) => Some(&e.error),
21            LineLoginError::HttpError(_) => None,
22            LineLoginError::SystemError(_) => None,
23        }
24    }
25}
26
27impl From<LineApiError> for LineLoginError {
28    fn from(value: LineApiError) -> Self {
29        LineLoginError::ApiError(value)
30    }
31}
32
33impl From<LineHttpError> for LineLoginError {
34    fn from(value: LineHttpError) -> Self {
35        LineLoginError::HttpError(value)
36    }
37}
38
39impl From<LineSystemError> for LineLoginError {
40    fn from(value: LineSystemError) -> Self {
41        LineLoginError::SystemError(value)
42    }
43}
44
45#[derive(Debug, Serialize, Deserialize, Clone)]
46pub struct LineApiError {
47    pub status: u16,
48    pub error: LineApiErrorResponse,
49    pub warnings: Option<Vec<String>>,
50    pub http_response_body: Option<String>,
51}
52
53/// https://developers.line.biz/ja/reference/messaging-api/#error-responses
54#[derive(Debug, Serialize, Deserialize, Clone)]
55pub struct LineApiErrorResponse {
56    pub error: String,
57    pub error_description: String,
58}
59
60#[derive(Debug, Clone)]
61pub struct LineHttpError {
62    pub status: u16,
63    pub http_response_body: Option<String>,
64}
65
66impl LineHttpError {
67    pub fn new(status: u16, http_response_body: String) -> LineHttpError {
68        LineHttpError {
69            status,
70            http_response_body: Some(http_response_body),
71        }
72    }
73}
74
75#[derive(Debug, Clone)]
76pub struct LineSystemError {
77    pub message: Option<String>,
78}
79
80impl LineSystemError {
81    pub fn new(message: String) -> LineSystemError {
82        LineSystemError {
83            message: Some(message),
84        }
85    }
86}