Skip to content

Commit

Permalink
Fix:Manage Firefox and Safari Network error message (#44929)
Browse files Browse the repository at this point in the history
Not all browsers implement the network error message in the same way:
For example if I execute `fetch('//foo.bar/').catch(err =>
console.log(err.message))` in Chrome / Firefox / Safari browsers
console, I get respectively:
- `Failed to fetch`
- `NetworkError when attempting to fetch resource.`
- `Load failed`

This PR fixes it.

## Bug

- [x] Related issues linked using fixes
[#45190](#45190)
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
dtrucs and ijjk committed Jan 26, 2023
1 parent 57ba24e commit d45df25
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/next/src/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,14 @@ function fetchNextData({
if (!unstable_skipClientCache) {
delete inflightCache[cacheKey]
}
if (err.message === 'Failed to fetch') {
if (
// chrome
err.message === 'Failed to fetch' ||
// firefox
err.message === 'NetworkError when attempting to fetch resource.' ||
// safari
err.message === 'Load failed'
) {
markAssetError(err)
}
throw err
Expand Down

0 comments on commit d45df25

Please sign in to comment.