Nicer log line on ws disconnect

This commit is contained in:
Andras Schmelczer 2025-06-07 17:15:56 +01:00
parent 4ca55768c5
commit ebbececdc9
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 31 additions and 27 deletions

View file

@ -1,13 +1,11 @@
use std::fmt::Display;
use aide::OperationOutput;
use axum::{
Json,
http::StatusCode,
response::{IntoResponse, Response},
};
use log::{error, info};
use schemars::JsonSchema;
use log::{debug, error};
use serde::Serialize;
use thiserror::Error;
@ -45,7 +43,7 @@ impl SyncServerError {
}
}
#[derive(Debug, Clone, Serialize, JsonSchema)]
#[derive(Debug, Clone, Serialize)]
pub struct SerializedError {
pub message: String,
pub causes: Vec<String>,
@ -96,35 +94,32 @@ impl From<&anyhow::Error> for SerializedError {
}
}
impl OperationOutput for SyncServerError {
type Inner = Self;
}
pub const fn init_error(error: anyhow::Error) -> SyncServerError {
pub fn init_error(error: anyhow::Error) -> SyncServerError {
debug!("Initialization error: {error:?}");
SyncServerError::InitError(error)
}
pub fn server_error(error: anyhow::Error) -> SyncServerError {
error!("Server error: {error:?}");
debug!("Server error: {error:?}");
SyncServerError::ServerError(error)
}
pub fn client_error(error: anyhow::Error) -> SyncServerError {
info!("Client error: {error:?}");
debug!("Client error: {error:?}");
SyncServerError::ClientError(error)
}
pub fn not_found_error(error: anyhow::Error) -> SyncServerError {
info!("Not found: {error:?}");
debug!("Not found: {error:?}");
SyncServerError::NotFound(error)
}
pub fn unauthenticated_error(error: anyhow::Error) -> SyncServerError {
info!("Unauthenticated user: {error:?}");
debug!("Unauthenticated user: {error:?}");
SyncServerError::Unauthenticated(error)
}
pub fn permission_denied_error(error: anyhow::Error) -> SyncServerError {
info!("Permission denied: {error:?}");
debug!("Permission denied: {error:?}");
SyncServerError::PermissionDeniedError(error)
}