mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-26 18:09:06 -04:00
fix: treat HTTP 400 responses as errors in npm resolver fetch (#10945)
This commit is contained in:
8
.changeset/fix-npm-resolver-400-status.md
Normal file
8
.changeset/fix-npm-resolver-400-status.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@pnpm/npm-resolver": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
fix: treat HTTP 400 responses as errors in the npm resolver fetch
|
||||
|
||||
The status check used `> 400` instead of `>= 400`, causing 400 Bad Request responses to bypass the error path and fall into JSON parse/retry logic instead.
|
||||
@@ -88,7 +88,7 @@ export async function fetchMetadataFromFromRegistry (
|
||||
reject(new PnpmError('META_FETCH_FAIL', `GET ${uri}: ${error.message as string}`, { attempts: attempt }))
|
||||
return
|
||||
}
|
||||
if (response.status > 400) {
|
||||
if (response.status >= 400) {
|
||||
const request = {
|
||||
authHeaderValue,
|
||||
url: uri,
|
||||
|
||||
@@ -942,6 +942,31 @@ test('error is thrown when package needs authorization', async () => {
|
||||
)
|
||||
})
|
||||
|
||||
test('error is thrown when registry returns 400 Bad Request', async () => {
|
||||
nock(registries.default)
|
||||
.get('/bad-pkg')
|
||||
.reply(400)
|
||||
|
||||
const { resolveFromNpm } = createResolveFromNpm({
|
||||
storeDir: temporaryDirectory(),
|
||||
cacheDir: temporaryDirectory(),
|
||||
registries,
|
||||
})
|
||||
await expect(resolveFromNpm({ alias: 'bad-pkg', bareSpecifier: '1.0.0' }, {})).rejects
|
||||
.toThrow(
|
||||
new RegistryResponseError(
|
||||
{
|
||||
url: `${registries.default}bad-pkg`,
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
statusText: '',
|
||||
},
|
||||
'bad-pkg'
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
test('error is thrown when there is no package found for the requested range', async () => {
|
||||
nock(registries.default)
|
||||
.get('/is-positive')
|
||||
|
||||
Reference in New Issue
Block a user