Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(errors): add GenericDuplicateError inApiErrorResponse #1792

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/router/src/compatibility/stripe/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pub enum StripeErrorCode {
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "{message}")]
GenericNotFoundError { message: String },

#[error(error_type = StripeErrorType::InvalidRequestError, code = "duplicate_resource", message = "{message}")]
GenericDuplicateError { message: String },

#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such merchant account")]
MerchantAccountNotFound,

Expand Down Expand Up @@ -411,6 +414,9 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
errors::ApiErrorResponse::GenericNotFoundError { message } => {
Self::GenericNotFoundError { message }
}
errors::ApiErrorResponse::GenericDuplicateError { message } => {
Self::GenericDuplicateError { message }
}
// parameter unknown, invalid request error // actually if we type wrong values in address we get this error. Stripe throws parameter unknown. I don't know if stripe is validating email and stuff
errors::ApiErrorResponse::InvalidDataFormat {
field_name,
Expand Down Expand Up @@ -607,6 +613,7 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::PaymentIntentMandateInvalid { .. }
| Self::PaymentIntentUnexpectedState { .. }
| Self::DuplicatePayment { .. }
| Self::GenericDuplicateError { .. }
| Self::IncorrectConnectorNameGiven
| Self::ResourceMissing { .. }
| Self::FileValidationFailed
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/errors/api_error_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ pub enum ApiErrorResponse {
MissingFileContentType,
#[error(error_type = ErrorType::InvalidRequestError, code = "HE_05", message = "{message}")]
GenericNotFoundError { message: String },
#[error(error_type = ErrorType::InvalidRequestError, code = "HE_01", message = "{message}")]
GenericDuplicateError { message: String },
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_01", message = "Failed to authenticate the webhook")]
WebhookAuthenticationFailed,
#[error(error_type = ErrorType::ObjectNotFound, code = "WE_04", message = "Webhook resource not found")]
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/core/errors/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon
Self::DuplicatePayout { payout_id } => {
AER::BadRequest(ApiError::new("HE", 1, format!("The payout with the specified payout_id '{payout_id}' already exists in our records"), None))
}
Self::GenericDuplicateError { message } => {
AER::BadRequest(ApiError::new("HE", 1, message, None))
}
Self::RefundNotFound => {
AER::NotFound(ApiError::new("HE", 2, "Refund does not exist in our records.", None))
}
Expand Down