mailjet_rs/client/error.rs
1use crate::client::StatusCode;
2use hyper::body::to_bytes;
3use hyper::Body;
4
5#[derive(Debug)]
6pub struct Error {
7 pub status_code: StatusCode,
8 pub message: String,
9}
10
11impl Error {
12 /// Creates an `Error` instance from the API response
13 pub async fn from_api_response(status_code: StatusCode, body: Body) -> Self {
14 let bytes = to_bytes(body).await.unwrap();
15 let body = String::from_utf8(bytes.to_vec()).expect("response was not valid utf-8");
16
17 Self {
18 status_code,
19 message: body,
20 }
21 }
22}