Improve logging and set .cfg config file ending
This commit is contained in:
parent
e2dc5f8857
commit
6a6bb2a4ce
6 changed files with 137 additions and 65 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue