Skip to content

Commit

Permalink
esm: throw on any non-2xx response
Browse files Browse the repository at this point in the history
Treat redirects without Location and other 3xx responses as errors

PR-URL: nodejs/node#43742
Refs: nodejs/node#43689
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
  • Loading branch information
LiviaMedeiros authored and guangwong committed Oct 10, 2022
1 parent 710c66d commit 910586f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/modules/esm/fetch_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ function fetchWithRedirects(parsed) {
err.message = `Cannot find module '${parsed.href}', HTTP 404`;
throw err;
}
if (res.statusCode < 200 || res.statusCode >= 400) {
// This condition catches all unsupported status codes, including
// 3xx redirection codes without `Location` HTTP header.
if (res.statusCode < 200 || res.statusCode >= 300) {
throw new ERR_NETWORK_IMPORT_DISALLOWED(
res.headers.location,
parsed.href,
Expand Down

0 comments on commit 910586f

Please sign in to comment.