1- use hyper:: { Method , StatusCode } ;
1+ use hyper:: { Method , StatusCode } ;
22use serde:: Serialize ;
3+ use std:: fmt;
34
45#[ derive( Debug ) ]
56pub ( crate ) enum Error {
67 WrongJson ( serde_json:: Error ) ,
78 NotFound ( NotFoundError ) ,
89 MsgNotSupported ( MsgNotSupportedError ) ,
10+ ModelNotFound ( String ) ,
911}
1012
1113#[ derive( Serialize , Debug ) ]
@@ -39,6 +41,7 @@ impl Error {
3941 Self :: WrongJson ( ..) => StatusCode :: BAD_REQUEST ,
4042 Self :: NotFound ( ..) => StatusCode :: NOT_FOUND ,
4143 Self :: MsgNotSupported ( ..) => StatusCode :: BAD_REQUEST ,
44+ Self :: ModelNotFound ( ..) => StatusCode :: NOT_FOUND ,
4245 }
4346 }
4447
@@ -48,6 +51,20 @@ impl Error {
4851 Self :: WrongJson ( e) => e. to_string ( ) ,
4952 Self :: NotFound ( e) => serde_json:: to_string ( & e) . unwrap ( ) ,
5053 Self :: MsgNotSupported ( e) => serde_json:: to_string ( & e) . unwrap ( ) ,
54+ Self :: ModelNotFound ( model) => format ! ( "Model not found: {}" , model) ,
5155 }
5256 }
5357}
58+
59+ impl fmt:: Display for Error {
60+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
61+ match self {
62+ Error :: WrongJson ( e) => write ! ( f, "Invalid JSON: {}" , e) ,
63+ Error :: NotFound ( e) => write ! ( f, "Not Found: {} {}" , e. method, e. uri) ,
64+ Error :: MsgNotSupported ( e) => write ! ( f, "Message type not supported: {:?}" , e. message) ,
65+ Error :: ModelNotFound ( model) => write ! ( f, "Model not found: {}" , model) ,
66+ }
67+ }
68+ }
69+
70+ impl std:: error:: Error for Error { }
0 commit comments