Skip to content

Commit

Permalink
Change EntityApiErrorType to EntityApiError
Browse files Browse the repository at this point in the history
  • Loading branch information
jhodapp committed Nov 30, 2023
1 parent 7a065c5 commit 8d17395
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions entity_api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ pub struct Error {
// Underlying error emitted from seaORM internals
pub inner: DbErr,
// Enum representing which category of error
pub error_type: EntityApiErrorType,
pub error_type: EntityApiError,
}

#[derive(Debug)]
pub enum EntityApiErrorType {
pub enum EntityApiError {
DatabaseConnectionLost,
// Record not found
RecordNotFound,
Expand All @@ -39,27 +39,27 @@ impl From<DbErr> for Error {
match err {
DbErr::RecordNotFound(_) => Error {
inner: err,
error_type: EntityApiErrorType::RecordNotFound,
error_type: EntityApiError::RecordNotFound,
},
DbErr::RecordNotUpdated => Error {
inner: err,
error_type: EntityApiErrorType::RecordNotUpdated,
error_type: EntityApiError::RecordNotUpdated,
},
DbErr::ConnectionAcquire(_) => Error {
inner: err,
error_type: EntityApiErrorType::SystemError,
error_type: EntityApiError::SystemError,
},
DbErr::Conn(_) => Error {
inner: err,
error_type: EntityApiErrorType::DatabaseConnectionLost,
error_type: EntityApiError::DatabaseConnectionLost,
},
DbErr::Exec(_) => Error {
inner: err,
error_type: EntityApiErrorType::SystemError,
error_type: EntityApiError::SystemError,
},
_ => Error {
inner: err,
error_type: EntityApiErrorType::SystemError,
error_type: EntityApiError::SystemError,
},
}
}
Expand Down
16 changes: 8 additions & 8 deletions web/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use serde::Serialize;

use entity_api::error::EntityApiErrorType;
use entity_api::error::Error as EntityApiError;
use entity_api::error::EntityApiError;
use entity_api::error::Error as EntityApiErrorSuper;

pub type Result<T> = core::result::Result<T, Error>;

Expand Down Expand Up @@ -45,13 +45,13 @@ impl IntoResponse for Error {
}
}

impl From<EntityApiError> for Error {
fn from(err: EntityApiError) -> Self {
impl From<EntityApiErrorSuper> for Error {
fn from(err: EntityApiErrorSuper) -> Self {
match err.error_type {
EntityApiErrorType::DatabaseConnectionLost => Error::DatabaseConnectionLost,
EntityApiErrorType::RecordNotFound => Error::EntityNotFound,
EntityApiErrorType::RecordNotUpdated => Error::UnprocessableEntity,
EntityApiErrorType::SystemError => Error::InternalServer,
EntityApiError::DatabaseConnectionLost => Error::DatabaseConnectionLost,
EntityApiError::RecordNotFound => Error::EntityNotFound,
EntityApiError::RecordNotUpdated => Error::UnprocessableEntity,
EntityApiError::SystemError => Error::InternalServer,
}
}
}

0 comments on commit 8d17395

Please sign in to comment.