Skip to content

Commit e2aab55

Browse files
committed
isKnownError
1 parent 4608c88 commit e2aab55

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

examples/cookbook/app/network-requests/PhoneBook.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ContactsList from './components/ContactsList';
55
import FavoritesList from './components/FavoritesList';
66
import getAllContacts from './api/getAllContacts';
77
import getAllFavorites from './api/getAllFavorites';
8+
import { isAxiosError } from 'axios';
89

910
export default () => {
1011
const [usersData, setUsersData] = useState<User[]>([]);
@@ -25,7 +26,8 @@ export default () => {
2526
try {
2627
await Promise.all([_getAllContacts(), _getAllFavorites()]);
2728
} catch (e) {
28-
const message = 'message' in e ? e.message : 'Something went wrong';
29+
const isKnownError = e instanceof Error || isAxiosError(e);
30+
const message = isKnownError ? e.message : 'Something went wrong';
2931
setError(message);
3032
}
3133
};

0 commit comments

Comments
 (0)