Deserialization and error handling improvements

This commit is contained in:
2024-02-07 07:43:11 +00:00
parent 450fe84d8b
commit 8c42901ddf
5 changed files with 73 additions and 20 deletions

View File

@@ -1,5 +1,7 @@
use std::fmt::Display;
use crate::types;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
@@ -8,6 +10,7 @@ pub enum Error {
HttpClient(reqwest::Error),
Token(gcp_auth::Error),
Serde(serde_json::Error),
VertexError(types::Error),
}
impl Display for Error {
@@ -17,6 +20,9 @@ impl Display for Error {
Error::HttpClient(e) => write!(f, "HTTP Client error: {}", e),
Error::Token(e) => write!(f, "Token error: {}", e),
Error::Serde(e) => write!(f, "Serde error: {}", e),
Error::VertexError(e) => {
write!(f, "Vertex error: {}", serde_json::to_string(e).unwrap())
}
}
}
}
@@ -46,3 +52,9 @@ impl From<serde_json::Error> for Error {
Error::Serde(e)
}
}
impl From<types::Error> for Error {
fn from(e: types::Error) -> Self {
Error::VertexError(e)
}
}