mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	fix(router/webhooks): use api error response for returning errors from webhooks core (#1305)
This commit is contained in:
		| @ -1,4 +1,7 @@ | ||||
| use error_stack::ResultExt; | ||||
|  | ||||
| use crate::{ | ||||
|     core::errors, | ||||
|     db::{get_and_deserialize_key, StorageInterface}, | ||||
|     types::api, | ||||
| }; | ||||
| @ -45,3 +48,30 @@ 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::WebhookEventTypeNotFound | ||||
|                 | errors::ConnectorError::WebhookResourceObjectNotFound | ||||
|                 | errors::ConnectorError::WebhookBodyDecodingFailed => { | ||||
|                     Err(e).change_context(errors::ApiErrorResponse::WebhookBadRequest) | ||||
|                 } | ||||
|  | ||||
|                 _ => Err(e).change_context(errors::ApiErrorResponse::InternalServerError), | ||||
|             }, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 ItsMeShashank
					ItsMeShashank