Skip to content

Commit

Permalink
cleanup: safely get pg conn in create_message_query
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptrunedev authored and cdxker committed Aug 26, 2024
1 parent 50d437b commit bc16798
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/src/operators/message_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ pub async fn create_message_query(
) -> Result<(), ServiceError> {
use crate::data::schema::messages::dsl::messages;

let mut conn = pool.get().await.unwrap();
let mut conn = match pool.get().await {
Ok(conn) => conn,
Err(e) => {
log::error!("Error getting connection from pool: {:?}", e);
return Err(ServiceError::InternalServerError(
"Error getting postgres connection from pool".into(),
));
}
};

diesel::insert_into(messages)
.values(&new_message)
Expand Down

0 comments on commit bc16798

Please sign in to comment.