-
Notifications
You must be signed in to change notification settings - Fork 18
/
error.rs
73 lines (67 loc) · 1.77 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::core::error::{Error as BError, RepoError};
use diesel::r2d2;
use diesel_migrations::RunMigrationsError;
use serde_json;
use std::{error, io};
use diesel::result::Error as DieselError;
impl From<RepoError> for AppError {
fn from(err: RepoError) -> AppError {
AppError::Business(BError::Repo(err))
}
}
impl From<DieselError> for RepoError {
fn from(err: DieselError) -> RepoError {
match err {
DieselError::NotFound => RepoError::NotFound,
_ => RepoError::Other(Box::new(err)),
}
}
}
impl From<RunMigrationsError> for AppError {
fn from(err: RunMigrationsError) -> AppError {
AppError::Other(Box::new(err))
}
}
quick_error! {
#[derive(Debug)]
pub enum AppError {
Business(err: BError){
from()
cause(err)
description(err.description())
}
Serialize(err: serde_json::Error){
from()
cause(err)
description(err.description())
}
Other(err: Box<error::Error + Send + Sync>){
from()
description(err.description())
from(err: io::Error) -> (Box::new(err))
}
R2d2(err: r2d2::PoolError){
from()
}
Toml(err: ::toml::de::Error){
from()
}
CsvIntoInner(err: ::csv::IntoInnerError<::csv::Writer<::std::vec::Vec<u8>>>){
from()
}
String(err: ::std::string::FromUtf8Error){
from()
}
Str(err: ::std::str::Utf8Error){
from()
}
Csv(err: ::csv::Error){
from()
}
}
}
impl From<failure::Error> for AppError {
fn from(from: failure::Error) -> Self {
AppError::Other(Box::new(from.compat()))
}
}