Skip to content

Commit c993d52

Browse files
KyleAMathewspvdz
andauthored
fix(gatsby-dev-cli): Correctly catch 404s from NPM when a package hasn't been published yet (#28297)
* fix(gatsby-dev-cli): Correctly catch 404s from NPM when a package hasn't been published yet * Use async/await Co-authored-by: Peter van der Zee <[email protected]> Co-authored-by: Peter van der Zee <[email protected]>
1 parent 9c7c1a2 commit c993d52

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

packages/gatsby-dev-cli/src/utils/check-deps-changes.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,13 @@ exports.checkDepsChanges = async ({
6060
// this allow us to not publish to local repository
6161
// and save some time/work
6262
try {
63-
localPKGjson = await new Promise((resolve, reject) => {
64-
got(`https://unpkg.com/${packageName}/package.json`).then(
65-
(error, response) => {
66-
if (response && response.statusCode === 200) {
67-
return resolve(JSON.parse(response.body))
68-
}
69-
70-
return reject(error)
71-
}
72-
)
73-
})
63+
const response = await got(
64+
`https://unpkg.com/${packageName}/package.json`
65+
)
66+
if (response?.statusCode !== 200) {
67+
throw new Error(`No response or non 200 code`)
68+
}
69+
localPKGjson = JSON.parse(response.body)
7470
} catch {
7571
console.log(
7672
`'${packageName}' doesn't seem to be installed and is not published on NPM.`

0 commit comments

Comments
 (0)