Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move find_all to entity_api #15

Closed
wants to merge 7 commits into from
Closed
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
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;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's talk through this when we meet later today. I think you've definitely exposed a part of how this is set up that could use more thought. I'm not sure I love adding the Super since to me that implies inheritance or nesting. But I also don't have a better option in mind off-hand.

Copy link
Member

@jhodapp jhodapp Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I borrowed the Super nomenclature from Rust modules which I think makes this fair. My approach also localizes the name distinction to this module only instead of EntityApiErrorType having "Type" always. From my understanding of Rust convention in the community, adding "Type" to the end of a type is not a common practice. It is in C/C++ land, but not Rust.


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,
}
}
}