Skip to content

Commit

Permalink
Add context to DbConnectionError
Browse files Browse the repository at this point in the history
  • Loading branch information
pawurb committed Jan 24, 2024
1 parent 2519dbd commit ebfa629
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub enum PgExtrasError {
#[error("Both $DATABASE_URL and $PG_EXTRAS_DATABASE_URL are not set")]
MissingConfigVars(),
#[error("Cannot connect to database")]
DbConnectionError(),
DbConnectionError(String),
#[error("Unknown pg-extras error")]
Unknown(String),
}
Expand All @@ -330,12 +330,12 @@ async fn get_rows<T: Tabular>(query: &str) -> Result<Vec<T>, PgExtrasError> {
.await
{
Ok(pool) => pool,
Err(_) => return Err(PgExtrasError::DbConnectionError()),
Err(e) => return Err(PgExtrasError::DbConnectionError(format!("{}", e))),
};

Ok(match sqlx::query(query).fetch_all(&pool).await {
Ok(rows) => rows.iter().map(T::new).collect(),
Err(e) => return Err(PgExtrasError::Unknown(format!("An error occurred: {}", e))),
Err(e) => return Err(PgExtrasError::Unknown(format!("{}", e))),
})
}

Expand Down

0 comments on commit ebfa629

Please sign in to comment.