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