Skip to content

Commit

Permalink
fix: return AddressNotFound instead of EntityError
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Jun 24, 2023
1 parent 0a26f5f commit db62967
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/address/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub enum AddressError {
ExternalIdAlreadyExists,
#[error("AddressError - external_id does not exist")]
ExternalIdNotFound,
#[error("AddressError - Could not find address: {0}")]
AddressNotFound(String),
#[error("AddressError - Sqlx: {0}")]
Sqlx(sqlx::Error),
#[error("AddressError - EntityError: {0}")]
Expand Down
5 changes: 5 additions & 0 deletions src/address/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ impl Addresses {
)
.fetch_all(&self.pool)
.await?;

if rows.is_empty() {
return Err(AddressError::AddressNotFound(address));
}

let mut events = EntityEvents::new();
for row in rows {
events.load_event(row.sequence as usize, row.event)?;
Expand Down
3 changes: 3 additions & 0 deletions src/api/server/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ impl From<ApplicationError> for tonic::Status {
ApplicationError::AddressError(AddressError::ExternalIdNotFound) => {
tonic::Status::not_found(err.to_string())
}
ApplicationError::AddressError(AddressError::AddressNotFound(_)) => {
tonic::Status::not_found(err.to_string())
}
ApplicationError::AddressError(AddressError::ExternalIdAlreadyExists) => {
tonic::Status::already_exists(err.to_string())
}
Expand Down

0 comments on commit db62967

Please sign in to comment.