From d623dd5ce80e39b5d9d1af9b3aed2f180766be2e Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Thu, 7 Jul 2022 21:13:26 +0200 Subject: [PATCH] less strict errors --- Cargo.lock | 2 +- ffplayout-api/Cargo.toml | 2 +- ffplayout-api/src/utils/control.rs | 2 +- ffplayout-api/src/utils/errors.rs | 8 +++++++- ffplayout-api/src/utils/files.rs | 2 +- ffplayout-api/src/utils/mod.rs | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7320121e..c5987b0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1027,7 +1027,7 @@ dependencies = [ [[package]] name = "ffplayout-api" -version = "0.4.0" +version = "0.4.1" dependencies = [ "actix-multipart", "actix-web", diff --git a/ffplayout-api/Cargo.toml b/ffplayout-api/Cargo.toml index 4ef87a66..39ac5720 100644 --- a/ffplayout-api/Cargo.toml +++ b/ffplayout-api/Cargo.toml @@ -4,7 +4,7 @@ description = "Rest API for ffplayout" license = "GPL-3.0" authors = ["Jonathan Baecker jonbae77@gmail.com"] readme = "README.md" -version = "0.4.0" +version = "0.4.1" edition = "2021" [dependencies] diff --git a/ffplayout-api/src/utils/control.rs b/ffplayout-api/src/utils/control.rs index 60d4949a..8b04e0bf 100644 --- a/ffplayout-api/src/utils/control.rs +++ b/ffplayout-api/src/utils/control.rs @@ -130,7 +130,7 @@ where Ok(result) => Ok(result), Err(e) => { error!("{e:?}"); - Err(ServiceError::BadRequest(e.to_string())) + Err(ServiceError::ServiceUnavailable(e.to_string())) } } } diff --git a/ffplayout-api/src/utils/errors.rs b/ffplayout-api/src/utils/errors.rs index a559ad75..3a7ba380 100644 --- a/ffplayout-api/src/utils/errors.rs +++ b/ffplayout-api/src/utils/errors.rs @@ -17,6 +17,9 @@ pub enum ServiceError { #[display(fmt = "NoContent: {}", _0)] NoContent(String), + + #[display(fmt = "ServiceUnavailable: {}", _0)] + ServiceUnavailable(String), } // impl ResponseError trait allows to convert our errors into http responses with appropriate data @@ -30,6 +33,9 @@ impl ResponseError for ServiceError { ServiceError::Conflict(ref message) => HttpResponse::Conflict().json(message), ServiceError::Unauthorized => HttpResponse::Unauthorized().json("No Permission!"), ServiceError::NoContent(ref message) => HttpResponse::NoContent().json(message), + ServiceError::ServiceUnavailable(ref message) => { + HttpResponse::ServiceUnavailable().json(message) + } } } } @@ -54,7 +60,7 @@ impl From for ServiceError { impl From for ServiceError { fn from(err: std::io::Error) -> ServiceError { - ServiceError::BadRequest(err.to_string()) + ServiceError::NoContent(err.to_string()) } } diff --git a/ffplayout-api/src/utils/files.rs b/ffplayout-api/src/utils/files.rs index 1c831cbd..3672990f 100644 --- a/ffplayout-api/src/utils/files.rs +++ b/ffplayout-api/src/utils/files.rs @@ -93,7 +93,7 @@ pub async fn browser(id: i64, path_obj: &PathObject) -> Result p.filter_map(|r| r.ok()).collect(), Err(e) => { error!("{e} in {}", path_obj.source); - return Err(ServiceError::InternalServerError); + return Err(ServiceError::NoContent(e.to_string())); } }; diff --git a/ffplayout-api/src/utils/mod.rs b/ffplayout-api/src/utils/mod.rs index 22ab49b1..fa8171b5 100644 --- a/ffplayout-api/src/utils/mod.rs +++ b/ffplayout-api/src/utils/mod.rs @@ -217,7 +217,7 @@ pub async fn read_log_file(channel_id: &i64, date: &str) -> Result