From ad4fe123e416ea4add9a052a1d3160c0d5b57b16 Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Tue, 25 Oct 2022 21:43:15 +0200 Subject: [PATCH] feat: error codes --- api/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/api/src/lib.rs b/api/src/lib.rs index 004f83a..57776a4 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -6,7 +6,7 @@ use portfolio_core::error::ServiceError; use portfolio_core::services::candidate_service::CandidateService; use requests::LoginRequest; use rocket::http::Status; -use rocket::{Rocket, Build, custom}; +use rocket::{Rocket, Build}; use rocket::serde::json::Json; use rocket::fairing::{self, AdHoc}; use rocket::response::status::Custom; @@ -27,9 +27,8 @@ pub use entity::candidate::Entity as Candidate; use portfolio_core::crypto::random_8_char_string; - -fn custom_err_from_service_err(err: ServiceError) -> Custom { - Custom(Status::InternalServerError, err.1.to_string()) +fn custom_err_from_service_err(service_err: ServiceError) -> Custom { + Custom(Status::from_code(service_err.0.code).unwrap_or_default(), service_err.1.to_string()) } #[post("/", data = "")]