Improve logging and set .cfg config file ending

This commit is contained in:
Tobias Reisinger 2026-08-31 20:44:08 +02:00
commit 6a6bb2a4ce
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
6 changed files with 137 additions and 65 deletions

View file

@ -1,6 +1,5 @@
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::io::ErrorKind;
use actix::MailboxError;
use actix_web::http::StatusCode;
@ -8,7 +7,8 @@ use actix_web::HttpResponse;
use config::ConfigError;
use serde::ser::SerializeStruct;
use serde::{Serialize, Serializer};
use tokio::sync::mpsc::error::SendError;
use tokio::sync::oneshot::error::RecvError;
use crate::errors::{ApiError, DatabaseError};
use crate::types::EmgauwaUid;
@ -45,13 +45,13 @@ impl From<&EmgauwaError> for String {
fn from(err: &EmgauwaError) -> Self {
match err {
EmgauwaError::Api(err) => String::from(err),
EmgauwaError::Unauthorized(_) => format!("unauthorized request: {}", err),
EmgauwaError::Unauthorized(err) => format!("unauthorized request: {}", err),
EmgauwaError::Serialization(_) => String::from("error during (de-)serialization"),
EmgauwaError::Database(err) => String::from(err),
EmgauwaError::Uid(_) => String::from("the uid is in a bad format"),
EmgauwaError::Internal(_) => String::from("internal error"),
EmgauwaError::Connection(uid) => {
format!("unable to connect to controller with uid: {}", uid)
format!("unable to connect to the controller with uid: {}", uid)
}
EmgauwaError::Other(err) => format!("other error: {}", err),
EmgauwaError::Hardware(err) => format!("hardware error: {}", err),
@ -101,6 +101,18 @@ impl From<ConfigError> for EmgauwaError {
}
}
impl<T> From<SendError<T>> for EmgauwaError {
fn from(value: SendError<T>) -> Self {
Self::Internal(value.to_string())
}
}
impl From<RecvError> for EmgauwaError {
fn from(value: RecvError) -> Self {
Self::Internal(value.to_string())
}
}
impl From<&EmgauwaError> for HttpResponse {
fn from(err: &EmgauwaError) -> Self {
HttpResponse::build(err.get_code()).json(err)
@ -111,7 +123,7 @@ impl Error for EmgauwaError {}
impl From<EmgauwaError> for std::io::Error {
fn from(value: EmgauwaError) -> Self {
std::io::Error::new(ErrorKind::Other, value)
std::io::Error::other(value)
}
}