use cloudflare::framework::response::ApiFailure;
pub fn format_error(e: ApiFailure, err_helper: Option<&dyn Fn(u16) -> &'static str>) -> String {
match e {
ApiFailure::Error(_, api_errors) => {
let mut complete_err = "".to_string();
for error in api_errors.errors {
let error_msg = format!("Code {}: {}\n", error.code, error.message);
if let Some(annotate_help) = err_helper {
let suggestion_text = annotate_help(error.code);
let help_msg = format!("{}\n", suggestion_text);
complete_err.push_str(&format!("{}{}", error_msg, help_msg));
} else {
complete_err.push_str(&error_msg)
}
}
complete_err.trim_end().to_string() }
ApiFailure::Invalid(reqwest_err) => format!("Error: {}", reqwest_err),
}
}