Skip to content

Commit

Permalink
Merge pull request #42 from kanko-travel/fix-sqlx-error-handling
Browse files Browse the repository at this point in the history
treat non protocol or io errors as bad requests
  • Loading branch information
umran authored Oct 24, 2024
2 parents 0ff9ff4 + 36402de commit b831209
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions model/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ impl std::error::Error for Error {
}

impl From<sqlx::Error> for Error {
fn from(err: sqlx::Error) -> Self {
match err {
sqlx::Error::RowNotFound => {
Error::not_found("no rows returned from query that expected at least one row")
fn from(value: sqlx::Error) -> Self {
use sqlx::Error::*;
match &value {
Tls(_) | Protocol(_) | Io(_) | PoolClosed | WorkerCrashed | PoolTimedOut => {
Error::internal(&value.to_string())
}
_ => Error::internal(&err.to_string()),
RowNotFound => Error::not_found(&value.to_string()),
_ => Error::bad_request(&value.to_string()),
}
}
}

0 comments on commit b831209

Please sign in to comment.