File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
examples/cookbook/app/network-requests Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import ContactsList from './components/ContactsList';
5
5
import FavoritesList from './components/FavoritesList' ;
6
6
import getAllContacts from './api/getAllContacts' ;
7
7
import getAllFavorites from './api/getAllFavorites' ;
8
- import { isAxiosError } from 'axios' ;
9
8
10
9
export default ( ) => {
11
10
const [ usersData , setUsersData ] = useState < User [ ] > ( [ ] ) ;
@@ -26,8 +25,7 @@ export default () => {
26
25
try {
27
26
await Promise . all ( [ _getAllContacts ( ) , _getAllFavorites ( ) ] ) ;
28
27
} catch ( e ) {
29
- const isKnownError = e instanceof Error || isAxiosError ( e ) ;
30
- const message = isKnownError ? e . message : 'Something went wrong' ;
28
+ const message = isErrorWithMessage ( e ) ? e . message : 'Something went wrong' ;
31
29
setError ( message ) ;
32
30
}
33
31
} ;
@@ -46,3 +44,9 @@ export default () => {
46
44
</ >
47
45
) ;
48
46
} ;
47
+
48
+ const isErrorWithMessage = (
49
+ e : unknown ,
50
+ ) : e is {
51
+ message : string ;
52
+ } => typeof e === 'object' && e !== null && 'foo' in e ;
You can’t perform that action at this time.
0 commit comments