From dcfb83fb2069bfcf4642b03453253e35479bf3da Mon Sep 17 00:00:00 2001 From: fx Date: Tue, 24 Oct 2023 01:15:22 +0200 Subject: first ping impl baseline, doesnt work --- src/error.rs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index db2fc86..f143ee9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,5 @@ use std::error::Error; +use std::io; use axum::http::StatusCode; use axum::Json; use axum::response::{IntoResponse, Response}; @@ -8,21 +9,45 @@ use crate::auth::AuthError; #[derive(Debug)] pub enum WebolError { - Auth(AuthError), Generic, - Server(Box), + Auth(AuthError), + Ping(surge_ping::SurgeError), + DB(sqlx::Error), + IpParse(::Err), + BufferParse(std::num::ParseIntError), + Broadcast(io::Error), + Axum(axum::Error) } impl IntoResponse for WebolError { fn into_response(self) -> Response { let (status, error_message) = match self { - WebolError::Auth(err) => err.get(), - WebolError::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), - WebolError::Server(err) => { + Self::Auth(err) => err.get(), + Self::Generic => (StatusCode::INTERNAL_SERVER_ERROR, ""), + Self::Ping(err) => { + error!("Ping: {}", err.source().unwrap()); + (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") + }, + Self::IpParse(err) => { + error!("server error: {}", err.to_string()); + (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") + }, + Self::DB(err) => { + error!("server error: {}", err.to_string()); + (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") + }, + Self::Broadcast(err) => { + error!("server error: {}", err.to_string()); + (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") + }, + Self::BufferParse(err) => { + error!("server error: {}", err.to_string()); + (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") + }, + Self::Axum(err) => { error!("server error: {}", err.to_string()); (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") }, - }; let body = Json(json!({ "error": error_message, -- cgit v1.2.3