|
1 | 1 | use std::fmt::Debug;
|
2 | 2 |
|
3 |
| -use async_bb8_diesel::{AsyncRunQueryDsl, ConnectionError}; |
| 3 | +use async_bb8_diesel::AsyncRunQueryDsl; |
4 | 4 | use diesel::{
|
5 | 5 | associations::HasTable,
|
6 | 6 | debug_query,
|
|
93 | 93 | {
|
94 | 94 | Ok(value) => Ok(value),
|
95 | 95 | Err(err) => match err.current_context() {
|
96 |
| - ConnectionError::Query(DieselError::DatabaseError( |
97 |
| - diesel::result::DatabaseErrorKind::UniqueViolation, |
98 |
| - _, |
99 |
| - )) => Err(err).change_context(errors::DatabaseError::UniqueViolation), |
| 96 | + DieselError::DatabaseError(diesel::result::DatabaseErrorKind::UniqueViolation, _) => { |
| 97 | + Err(err).change_context(errors::DatabaseError::UniqueViolation) |
| 98 | + } |
100 | 99 | _ => Err(err).change_context(errors::DatabaseError::Others),
|
101 | 100 | },
|
102 | 101 | }
|
@@ -168,14 +167,12 @@ where
|
168 | 167 | logger::debug!(query = %debug_query::<Pg, _>(&query).to_string());
|
169 | 168 | Ok(result)
|
170 | 169 | }
|
171 |
| - Err(ConnectionError::Query(DieselError::QueryBuilderError(_))) => { |
| 170 | + Err(DieselError::QueryBuilderError(_)) => { |
172 | 171 | Err(report!(errors::DatabaseError::NoFieldsToUpdate))
|
173 | 172 | .attach_printable_lazy(|| format!("Error while updating {debug_values}"))
|
174 | 173 | }
|
175 |
| - Err(ConnectionError::Query(DieselError::NotFound)) => { |
176 |
| - Err(report!(errors::DatabaseError::NotFound)) |
177 |
| - .attach_printable_lazy(|| format!("Error while updating {debug_values}")) |
178 |
| - } |
| 174 | + Err(DieselError::NotFound) => Err(report!(errors::DatabaseError::NotFound)) |
| 175 | + .attach_printable_lazy(|| format!("Error while updating {debug_values}")), |
179 | 176 | _ => Err(report!(errors::DatabaseError::Others))
|
180 | 177 | .attach_printable_lazy(|| format!("Error while updating {debug_values}")),
|
181 | 178 | }
|
@@ -259,14 +256,12 @@ where
|
259 | 256 | logger::debug!(query = %debug_query::<Pg, _>(&query).to_string());
|
260 | 257 | Ok(result)
|
261 | 258 | }
|
262 |
| - Err(ConnectionError::Query(DieselError::QueryBuilderError(_))) => { |
| 259 | + Err(DieselError::QueryBuilderError(_)) => { |
263 | 260 | Err(report!(errors::DatabaseError::NoFieldsToUpdate))
|
264 | 261 | .attach_printable_lazy(|| format!("Error while updating by ID {debug_values}"))
|
265 | 262 | }
|
266 |
| - Err(ConnectionError::Query(DieselError::NotFound)) => { |
267 |
| - Err(report!(errors::DatabaseError::NotFound)) |
268 |
| - .attach_printable_lazy(|| format!("Error while updating by ID {debug_values}")) |
269 |
| - } |
| 263 | + Err(DieselError::NotFound) => Err(report!(errors::DatabaseError::NotFound)) |
| 264 | + .attach_printable_lazy(|| format!("Error while updating by ID {debug_values}")), |
270 | 265 | _ => Err(report!(errors::DatabaseError::Others))
|
271 | 266 | .attach_printable_lazy(|| format!("Error while updating by ID {debug_values}")),
|
272 | 267 | }
|
@@ -353,9 +348,7 @@ where
|
353 | 348 | {
|
354 | 349 | Ok(value) => Ok(value),
|
355 | 350 | Err(err) => match err.current_context() {
|
356 |
| - ConnectionError::Query(DieselError::NotFound) => { |
357 |
| - Err(err).change_context(errors::DatabaseError::NotFound) |
358 |
| - } |
| 351 | + DieselError::NotFound => Err(err).change_context(errors::DatabaseError::NotFound), |
359 | 352 | _ => Err(err).change_context(errors::DatabaseError::Others),
|
360 | 353 | },
|
361 | 354 | }
|
@@ -404,9 +397,7 @@ where
|
404 | 397 | .await
|
405 | 398 | .into_report()
|
406 | 399 | .map_err(|err| match err.current_context() {
|
407 |
| - ConnectionError::Query(DieselError::NotFound) => { |
408 |
| - err.change_context(errors::DatabaseError::NotFound) |
409 |
| - } |
| 400 | + DieselError::NotFound => err.change_context(errors::DatabaseError::NotFound), |
410 | 401 | _ => err.change_context(errors::DatabaseError::Others),
|
411 | 402 | })
|
412 | 403 | .attach_printable_lazy(|| "Error finding record by predicate")
|
|
0 commit comments