mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
refactor(router): remove WebhookApiErrorSwitch and implement error mapping using ErrorSwitch (#1660)
Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in>
This commit is contained in:
committed by
GitHub
parent
728177666b
commit
a7c66ddea2
@ -1,7 +1,4 @@
|
||||
use error_stack::ResultExt;
|
||||
|
||||
use crate::{
|
||||
core::errors,
|
||||
db::{get_and_deserialize_key, StorageInterface},
|
||||
types::api,
|
||||
};
|
||||
@ -48,34 +45,3 @@ pub async fn lookup_webhook_event(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WebhookApiErrorSwitch<T> {
|
||||
fn switch(self) -> errors::RouterResult<T>;
|
||||
}
|
||||
|
||||
impl<T> WebhookApiErrorSwitch<T> for errors::CustomResult<T, errors::ConnectorError> {
|
||||
fn switch(self) -> errors::RouterResult<T> {
|
||||
match self {
|
||||
Ok(res) => Ok(res),
|
||||
Err(e) => match e.current_context() {
|
||||
errors::ConnectorError::WebhookSourceVerificationFailed => {
|
||||
Err(e).change_context(errors::ApiErrorResponse::WebhookAuthenticationFailed)
|
||||
}
|
||||
|
||||
errors::ConnectorError::WebhookSignatureNotFound
|
||||
| errors::ConnectorError::WebhookReferenceIdNotFound
|
||||
| errors::ConnectorError::WebhookResourceObjectNotFound
|
||||
| errors::ConnectorError::WebhookBodyDecodingFailed
|
||||
| errors::ConnectorError::WebhooksNotImplemented => {
|
||||
Err(e).change_context(errors::ApiErrorResponse::WebhookBadRequest)
|
||||
}
|
||||
|
||||
errors::ConnectorError::WebhookEventTypeNotFound => {
|
||||
Err(e).change_context(errors::ApiErrorResponse::WebhookUnprocessableEntity)
|
||||
}
|
||||
|
||||
_ => Err(e).change_context(errors::ApiErrorResponse::InternalServerError),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user