1- use leptos:: config:: errors:: LeptosConfigError ;
1+ use leptos:: { config:: errors:: LeptosConfigError } ;
2+ use tonic:: Status ;
23use tracing:: error;
34
45/// This is custom Result type for the application.
@@ -8,6 +9,10 @@ pub type Result<T> = core::result::Result<T, Error>;
89#[ derive( Debug , Clone ) ]
910pub enum Error {
1011 Generic ( String ) ,
12+
13+ /// Error when the password encryption has some issue.
14+ Argon2 ( Box < argon2:: password_hash:: Error > ) ,
15+
1116}
1217
1318impl core:: fmt:: Display for Error {
@@ -30,6 +35,40 @@ impl From<surrealdb::Error> for Error {
3035 }
3136}
3237
38+ impl From < argon2:: password_hash:: Error > for Error {
39+ fn from ( actual_error : argon2:: password_hash:: Error ) -> Self {
40+ error ! ( "argon2 password hash error: {actual_error:?}" ) ;
41+ Self :: Argon2 ( Box :: new ( actual_error) )
42+ }
43+ }
44+
45+ impl From < dotenvy:: Error > for Error {
46+ fn from ( val : dotenvy:: Error ) -> Self {
47+ error ! ( "there is an issue with loading env file: {val:?}" ) ;
48+ Self :: Generic ( "there is an issue with loading env file" . to_string ( ) )
49+ }
50+ }
51+
52+ impl From < Error > for Status {
53+ fn from ( val : Error ) -> Self {
54+ match val {
55+ // Error::InvalidArgument(error_response) => Self::invalid_argument(error_response),
56+ // Error::Unauthorizeed(resource_name) => {
57+ // let error_message = format!("unauthorized: you do not have access to access this ({resource_name}) resource");
58+ // Self::permission_denied(error_message)
59+ // }
60+ // Error::Unauthenticated(error_message) => {
61+ // Self::unauthenticated(error_message)
62+ // },
63+ Error :: Argon2 ( boxed_error) => {
64+ Self :: internal ( format ! ( "Argon2 error: {boxed_error:?}" ) )
65+ } ,
66+ _ => Self :: invalid_argument ( "500 Internal server error" )
67+ }
68+ }
69+ }
70+
71+
3372impl From < std:: io:: Error > for Error {
3473 fn from ( error : std:: io:: Error ) -> Self {
3574 error ! ( "IO error: {error:?}" ) ;
0 commit comments