File tree Expand file tree Collapse file tree 2 files changed +41
-7
lines changed Expand file tree Collapse file tree 2 files changed +41
-7
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,12 +41,37 @@ export function LoginForm() {
41
41
description : "Login Failed." ,
42
42
} ) ;
43
43
}
44
- } catch ( err ) {
45
- toast ( {
46
- title : "Error" ,
47
- variant : "destructive" ,
48
- description : "Login Failed." ,
49
- } ) ;
44
+ } catch ( err : unknown ) {
45
+ if ( err instanceof Error ) {
46
+ let description_text = "" ;
47
+ switch ( err . message ) {
48
+ case "Email and/or password is missing." :
49
+ description_text = "Please provide both email and password." ;
50
+ break ;
51
+ case "Invalid email or password." :
52
+ description_text = "Username or password is incorrect." ;
53
+ break ;
54
+ case "Internal server error. Please try again later." :
55
+ description_text =
56
+ "There was an issue with the server. Please try again later." ;
57
+ break ;
58
+ default :
59
+ description_text =
60
+ "An unexpected error occurred. Please try again." ;
61
+ break ;
62
+ }
63
+ toast ( {
64
+ title : "Error" ,
65
+ variant : "destructive" ,
66
+ description : description_text ,
67
+ } ) ;
68
+ } else {
69
+ toast ( {
70
+ title : "Error" ,
71
+ variant : "destructive" ,
72
+ description : "An unexpected error occurred. Please try again." ,
73
+ } ) ;
74
+ }
50
75
}
51
76
} ;
52
77
You can’t perform that action at this time.
0 commit comments