Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion burn-central-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ impl ResponseExt for reqwest::blocking::Response {
match self.status() {
reqwest::StatusCode::NOT_FOUND => Err(ClientError::NotFound),
reqwest::StatusCode::UNAUTHORIZED => Err(ClientError::Unauthorized),
reqwest::StatusCode::FORBIDDEN => Err(ClientError::Forbidden),
reqwest::StatusCode::INTERNAL_SERVER_ERROR => Err(ClientError::InternalServerError),
_ => Err(ClientError::ApiError {
status: self.status(),
Expand Down
14 changes: 10 additions & 4 deletions burn-central-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use thiserror::Error;
pub enum ApiErrorCode {
ProjectAlreadyExists,
UnsupportedSdkVersion,
LimitReached,
// ...
#[serde(other)]
Unknown,
Expand All @@ -31,7 +32,7 @@ impl Default for ApiErrorBody {

impl Display for ApiErrorBody {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Code: {}, Message: {}", self.code, self.message)
write!(f, "{}: {}", self.code, self.message)
}
}

Expand All @@ -43,8 +44,6 @@ pub enum ClientError {
NotFound,
#[error("Unauthorized access")]
Unauthorized,
#[error("Forbidden access")]
Forbidden,
#[error("Internal server error")]
InternalServerError,
#[error("Api error {status}: {body}")]
Expand All @@ -70,7 +69,14 @@ impl ClientError {
}
}

pub fn message(&self) -> Option<String> {
match self {
ClientError::ApiError { body, .. } => Some(body.message.clone()),
_ => None,
}
}

pub fn is_login_error(&self) -> bool {
matches!(self, ClientError::Unauthorized | ClientError::Forbidden)
matches!(self, ClientError::Unauthorized)
}
}
Loading