mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-17 18:05:42 +02:00
simplify error check logic
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
+3
-1
@@ -6,6 +6,7 @@ use bytes::{Bytes, BytesMut};
|
||||
use futures::stream::StreamExt;
|
||||
use futures_util::Stream;
|
||||
use size::Size;
|
||||
use tokio_postgres::error::SqlState;
|
||||
use tracing::*;
|
||||
|
||||
use crate::handlers::ApiError;
|
||||
@@ -167,7 +168,8 @@ async fn make_blob(pool: &Pool, s3_key: &String, hash: &str) -> Result<Option<St
|
||||
match postgres::insert_blob(&pool, &s3_key, &hash).await {
|
||||
Ok(_) => break Ok(None),
|
||||
Err(e) => {
|
||||
if postgres::is_unique_constraint_violation(&e) {
|
||||
if matches!(e, DbError::Db(ref db_err) if db_err.code() == Some(&SqlState::UNIQUE_VIOLATION))
|
||||
{
|
||||
debug!("concurrent upload detected");
|
||||
|
||||
if let Some(s3_key_found) = postgres::find_blob_by_hash(&pool, &hash).await? {
|
||||
|
||||
@@ -4,7 +4,6 @@ use bb8_postgres::PostgresConnectionManager;
|
||||
use bytes::Bytes;
|
||||
use serde::de::DeserializeOwned;
|
||||
use tokio_postgres::NoTls;
|
||||
use tokio_postgres::error::SqlState;
|
||||
use tokio_postgres::{self as pg};
|
||||
use tracing::*;
|
||||
|
||||
@@ -209,10 +208,3 @@ pub async fn set_part<D: serde::Serialize>(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_unique_constraint_violation(e: &DbError) -> bool {
|
||||
match e {
|
||||
DbError::Db(e) => e.code() == Some(&SqlState::UNIQUE_VIOLATION),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user