extract api-types crate, adopt thiserror for all errors
api-types: standalone crate with DTOs (widget, data source, layout, preset) extracted from http-api. Shared between http-api and future SPA. thiserror: replaced all manual Display impls with derive macros across 8 crates (config-sqlite, config-memory, tcp-server, tcp-client, http-json, rss, media, application).
This commit is contained in:
@@ -11,25 +11,18 @@ pub struct ConfigService<'a, C, E> {
|
||||
events: &'a E,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ConfigError<C: fmt::Debug, E: fmt::Debug> {
|
||||
#[error("repository error: {0:?}")]
|
||||
Repository(C),
|
||||
#[error("event error: {0:?}")]
|
||||
Event(E),
|
||||
#[error("validation errors: {0:?}")]
|
||||
Validation(Vec<DataSourceValidationError>),
|
||||
#[error("not found")]
|
||||
NotFound,
|
||||
}
|
||||
|
||||
impl<C: fmt::Debug, E: fmt::Debug> fmt::Display for ConfigError<C, E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
ConfigError::Repository(e) => write!(f, "repository error: {:?}", e),
|
||||
ConfigError::Event(e) => write!(f, "event error: {:?}", e),
|
||||
ConfigError::Validation(errors) => write!(f, "validation errors: {:?}", errors),
|
||||
ConfigError::NotFound => write!(f, "not found"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C, E> ConfigService<'a, C, E>
|
||||
where
|
||||
C: ConfigRepository,
|
||||
|
||||
Reference in New Issue
Block a user