File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,16 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
75
75
) ;
76
76
77
77
if ( ! response . ok ) {
78
- throw new Error ( "Not OK" ) ;
78
+ switch ( response . status ) {
79
+ case 400 :
80
+ throw new Error ( "Email and/or password is missing." ) ;
81
+ case 401 :
82
+ throw new Error ( "Invalid email or password." ) ;
83
+ case 500 :
84
+ throw new Error ( "Internal server error. Please try again later." ) ;
85
+ default :
86
+ throw new Error ( "Unexpected error occurred." ) ;
87
+ }
79
88
}
80
89
81
90
const resJson = await response . json ( ) ;
Original file line number Diff line number Diff line change @@ -41,11 +41,26 @@ export function LoginForm() {
41
41
description : "Login Failed." ,
42
42
} ) ;
43
43
}
44
- } catch ( err ) {
44
+ } catch ( err : any ) {
45
+ let description_text = "" ;
46
+ switch ( err . message ) {
47
+ case "Email and/or password is missing." :
48
+ description_text = "Please provide both email and password." ;
49
+ break ;
50
+ case "Invalid email or password." :
51
+ description_text = "Username or password is incorrect." ;
52
+ break ;
53
+ case "Internal server error. Please try again later." :
54
+ description_text = "There was an issue with the server. Please try again later." ;
55
+ break ;
56
+ default :
57
+ description_text = "An unexpected error occurred. Please try again." ;
58
+ break ;
59
+ }
45
60
toast ( {
46
61
title : "Error" ,
47
62
variant : "destructive" ,
48
- description : "Username or/and password provided is wrong." ,
63
+ description : description_text ,
49
64
} ) ;
50
65
}
51
66
} ;
You can’t perform that action at this time.
0 commit comments