1
1
use actix_session:: { SessionGetError , SessionInsertError } ;
2
- use std:: fmt:: { Display , Formatter } ;
3
2
4
3
use actix_web:: http:: StatusCode ;
4
+ use thiserror:: Error ;
5
5
use webauthn_rs:: prelude:: WebauthnError ;
6
6
7
7
pub ( crate ) mod auth;
@@ -16,42 +16,24 @@ type WebResult<T> = Result<T, Error>;
16
16
/**
17
17
Unified errors for simpler Responses
18
18
*/
19
- #[ derive( Debug ) ]
19
+ #[ derive( Debug , Error ) ]
20
20
pub ( crate ) enum Error {
21
+ #[ error( "Unknown webauthn error" ) ]
21
22
Unknown ( WebauthnError ) ,
22
- SessionGet ( SessionGetError ) ,
23
- SessionInsert ( SessionInsertError ) ,
23
+ #[ error( "Corrupt session" ) ]
24
+ SessionGet ( #[ from] SessionGetError ) ,
25
+ #[ error( "Corrupt session" ) ]
26
+ SessionInsert ( #[ from] SessionInsertError ) ,
27
+ #[ error( "Corrupt session" ) ]
24
28
CorruptSession ,
25
- BadRequest ( WebauthnError ) ,
29
+ #[ error( "Bad request" ) ]
30
+ BadRequest ( #[ from] WebauthnError ) ,
31
+ #[ error( "User not found" ) ]
26
32
UserNotFound ,
33
+ #[ error( "User has no credentials" ) ]
27
34
UserHasNoCredentials ,
28
35
}
29
36
30
- impl From < SessionGetError > for Error {
31
- fn from ( value : SessionGetError ) -> Self {
32
- Self :: SessionGet ( value)
33
- }
34
- }
35
-
36
- impl From < SessionInsertError > for Error {
37
- fn from ( value : SessionInsertError ) -> Self {
38
- Self :: SessionInsert ( value)
39
- }
40
- }
41
-
42
- impl Display for Error {
43
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
44
- match self {
45
- Error :: Unknown ( _) => write ! ( f, "Unknown webauthn error" ) ,
46
- Error :: SessionGet ( _) | Error :: SessionInsert ( _) => write ! ( f, "Corrupt session" ) ,
47
- Error :: BadRequest ( _) => write ! ( f, "Bad request" ) ,
48
- Error :: UserNotFound => write ! ( f, "User not found" ) ,
49
- Error :: UserHasNoCredentials => write ! ( f, "User has no credentials" ) ,
50
- Error :: CorruptSession => write ! ( f, "Corrupt session" ) ,
51
- }
52
- }
53
- }
54
-
55
37
impl actix_web:: ResponseError for Error {
56
38
fn status_code ( & self ) -> StatusCode {
57
39
StatusCode :: INTERNAL_SERVER_ERROR
0 commit comments