mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 21:07:58 +08:00
refactor(router): move db models into separate crate and refactoring around it (#125)
This commit is contained in:
@ -35,14 +35,17 @@ pub async fn create_customer(
|
||||
|
||||
let customer = match db.insert_customer(new_customer).await {
|
||||
Ok(customer) => customer,
|
||||
Err(error) => match error.current_context() {
|
||||
errors::StorageError::DatabaseError(errors::DatabaseError::UniqueViolation) => db
|
||||
.find_customer_by_customer_id_merchant_id(&customer_id, &merchant_id)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)?,
|
||||
_ => Err(error.change_context(errors::ApiErrorResponse::InternalServerError))?,
|
||||
},
|
||||
Err(error) => {
|
||||
if error.current_context().is_db_unique_violation() {
|
||||
db.find_customer_by_customer_id_merchant_id(&customer_id, &merchant_id)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)?
|
||||
} else {
|
||||
Err(error.change_context(errors::ApiErrorResponse::InternalServerError))?
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Ok(services::BachResponse::Json(customer.into()))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user