@@ -41,7 +41,12 @@ pub enum StorageError {
41
41
42
42
impl From < error_stack:: Report < RedisError > > for StorageError {
43
43
fn from ( err : error_stack:: Report < RedisError > ) -> Self {
44
- Self :: RedisError ( err)
44
+ match err. current_context ( ) {
45
+ RedisError :: NotFound => Self :: ValueNotFound ( "redis value not found" . to_string ( ) ) ,
46
+ RedisError :: JsonSerializationFailed => Self :: SerializationFailed ,
47
+ RedisError :: JsonDeserializationFailed => Self :: DeserializationFailed ,
48
+ _ => Self :: RedisError ( err) ,
49
+ }
45
50
}
46
51
}
47
52
@@ -53,7 +58,15 @@ impl From<diesel::result::Error> for StorageError {
53
58
54
59
impl From < error_stack:: Report < DatabaseError > > for StorageError {
55
60
fn from ( err : error_stack:: Report < DatabaseError > ) -> Self {
56
- Self :: DatabaseError ( err)
61
+ match err. current_context ( ) {
62
+ DatabaseError :: DatabaseConnectionError => Self :: DatabaseConnectionError ,
63
+ DatabaseError :: NotFound => Self :: ValueNotFound ( String :: from ( "db value not found" ) ) ,
64
+ DatabaseError :: UniqueViolation => Self :: DuplicateValue {
65
+ entity : "db entity" ,
66
+ key : None ,
67
+ } ,
68
+ _ => Self :: DatabaseError ( err) ,
69
+ }
57
70
}
58
71
}
59
72
@@ -72,6 +85,7 @@ impl StorageError {
72
85
Self :: DatabaseError ( err) => {
73
86
matches ! ( err. current_context( ) , DatabaseError :: UniqueViolation , )
74
87
}
88
+ Self :: DuplicateValue { .. } => true ,
75
89
_ => false ,
76
90
}
77
91
}
0 commit comments