File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 3
3
getValidationErrorMessage ,
4
4
isApiError ,
5
5
mapApiErrorToFieldErrors ,
6
+ getErrorMessage ,
6
7
} from "./errors" ;
7
8
8
9
describe ( "isApiError" , ( ) => {
@@ -82,4 +83,21 @@ describe("getValidationErrorMessage", () => {
82
83
) ,
83
84
) . toEqual ( "" ) ;
84
85
} ) ;
86
+
87
+ it ( "returns default message for error that is empty string" , ( ) => {
88
+ expect ( getErrorMessage ( "" , "Something went wrong." ) ) . toBe (
89
+ "Something went wrong." ,
90
+ ) ;
91
+ } ) ;
92
+
93
+ it ( "returns default message for 404 API response" , ( ) => {
94
+ expect (
95
+ getErrorMessage (
96
+ mockApiError ( {
97
+ message : "" ,
98
+ } ) ,
99
+ "Something went wrong." ,
100
+ ) ,
101
+ ) . toBe ( "Something went wrong." ) ;
102
+ } ) ;
85
103
} ) ;
Original file line number Diff line number Diff line change @@ -62,10 +62,13 @@ export const getErrorMessage = (
62
62
error : unknown ,
63
63
defaultMessage : string ,
64
64
) : string => {
65
- if ( isApiError ( error ) ) {
65
+ // if error is API error
66
+ // 404s result in the default message being returned
67
+ if ( isApiError ( error ) && error . response . data . message ) {
66
68
return error . response . data . message ;
67
69
}
68
- if ( typeof error === "string" ) {
70
+ // if error is a non-empty string
71
+ if ( error && typeof error === "string" ) {
69
72
return error ;
70
73
}
71
74
return defaultMessage ;
You can’t perform that action at this time.
0 commit comments