mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	Add a base struct for api error responses (#524)
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										28
									
								
								crates/api_models/src/errors/actix.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								crates/api_models/src/errors/actix.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| use super::types::ApiErrorResponse; | ||||
|  | ||||
| impl actix_web::ResponseError for ApiErrorResponse { | ||||
|     fn status_code(&self) -> reqwest::StatusCode { | ||||
|         use reqwest::StatusCode; | ||||
|  | ||||
|         match self { | ||||
|             Self::Unauthorized(_) => StatusCode::UNAUTHORIZED, | ||||
|             Self::ForbiddenCommonResource(_) => StatusCode::FORBIDDEN, | ||||
|             Self::ForbiddenPrivateResource(_) => StatusCode::NOT_FOUND, | ||||
|             Self::Conflict(_) => StatusCode::CONFLICT, | ||||
|             Self::Gone(_) => StatusCode::GONE, | ||||
|             Self::Unprocessable(_) => StatusCode::UNPROCESSABLE_ENTITY, | ||||
|             Self::InternalServerError(_) => StatusCode::INTERNAL_SERVER_ERROR, | ||||
|             Self::NotImplemented(_) => StatusCode::NOT_IMPLEMENTED, | ||||
|             Self::ConnectorError(_, code) => *code, | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fn error_response(&self) -> actix_web::HttpResponse { | ||||
|         use actix_web::http::header; | ||||
|  | ||||
|         actix_web::HttpResponseBuilder::new(self.status_code()) | ||||
|             .insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON)) | ||||
|             .insert_header((header::VIA, "Juspay_Router")) | ||||
|             .body(self.to_string()) | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sampras Lopes
					Sampras Lopes