square_api_client/models/errors/
api_error.rs1use super::Error;
2
3#[derive(Clone, Debug, Default)]
4pub struct ApiError {
5 pub message: String,
6 pub errors: Vec<Error>,
7}
8
9impl ApiError {
10 pub fn new(message: &str) -> Self {
11 Self {
12 message: message.to_owned(),
13 ..Default::default()
14 }
15 }
16
17 pub fn with_response_errors(message: &str, errors: &[Error]) -> Self {
18 Self {
19 message: message.to_owned(),
20 errors: errors.to_vec(),
21 }
22 }
23}
24
25impl std::fmt::Display for ApiError {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 write!(f, "API Error: {:?}", self)
28 }
29}
30
31impl std::error::Error for ApiError {
32 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
33 None
34 }
35}