1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use graphql_client::Error;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum ApiCallError {
    #[error("Request failed: {0}")]
    RequestFailed(String),
    #[error("Json parse fail: {0}")]
    JsonParse(String),
    #[error("Server returned: {0}")]
    DataError(String),
}

pub fn extract_error_message(errors_maybe: Option<Vec<Error>>) -> String {
    match errors_maybe {
        None => "Unknown error".to_string(),
        Some(errors) => {
            let errors: Vec<String> = errors.iter().map(|e| e.to_string()).collect();
            errors.join(" | ")
        }
    }
}