From 19a4e0c2998ba01170ba601a3b83cf4b3107b4a4 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Mon, 3 Jun 2024 16:36:43 +0400 Subject: [PATCH] style: cleanup UTF8 error throwing code --- src/web_server/app_error.rs | 2 +- src/web_server/old_device_sensor_api/mod.rs | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/web_server/app_error.rs b/src/web_server/app_error.rs index 9285dcc..32ab50d 100644 --- a/src/web_server/app_error.rs +++ b/src/web_server/app_error.rs @@ -45,7 +45,7 @@ pub enum AppError { }, #[display(fmt = "UTF8")] - Utf8Error(std::str::Utf8Error), + Utf8Error(#[from] std::str::Utf8Error), #[display(fmt = "IDK")] UnknownBody { diff --git a/src/web_server/old_device_sensor_api/mod.rs b/src/web_server/old_device_sensor_api/mod.rs index 33be26f..bfc31ae 100644 --- a/src/web_server/old_device_sensor_api/mod.rs +++ b/src/web_server/old_device_sensor_api/mod.rs @@ -5,7 +5,6 @@ pub mod qs_parser; use crate::ingest_protocol::NMJsonPacket; use crate::web_server::app_error::AppError; -use bstr::ByteSlice; use ntex::http::{HttpMessage, StatusCode}; use ntex::util::Bytes; use ntex::web::types::State; @@ -50,12 +49,7 @@ pub async fn device_handler<'a>( Err(error) => json_error = Some(error), }, "application/x-www-form-urlencoded" => { - let body = match std::str::from_utf8(body.as_ref()) { - Ok(body) => body, - Err(error) => { - return Err(AppError::Utf8Error(error)); - } - }; + let body = std::str::from_utf8(body.as_ref())?; match qs_parser::parse_nm_qs_format(body).await { Ok(qs_body) => { real_body = Some(NMJsonPacket {