diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d38f2f349..f9d4f6a6b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa [#6712](https://github.com/yarnpkg/yarn/pull/6712) - [**Maël Nison**](https://twitter.com/arcanis) +- Properly reports the error codes when the npm registry throws 500's + + [#6817](https://github.com/yarnpkg/yarn/pull/6817) - [**Maël Nison**](https://twitter.com/arcanis) + ## 1.12.3 **Important:** This release contains a cache bump. It will cause the very first install following the upgrade to take slightly more time, especially if you don't use the [Offline Mirror](https://yarnpkg.com/blog/2016/11/24/offline-mirror/) feature. After that everything will be back to normal. diff --git a/src/util/request-manager.js b/src/util/request-manager.js index b886f7c494..3e944f6b7f 100644 --- a/src/util/request-manager.js +++ b/src/util/request-manager.js @@ -498,8 +498,19 @@ export default class RequestManager { req.on('data', queue.stillActive.bind(queue)); } - if (params.process) { - params.process(req, resolve, reject); + const process = params.process; + if (process) { + req.on('response', res => { + if (res.statusCode >= 200 && res.statusCode < 300) { + return; + } + + const description = `${res.statusCode} ${http.STATUS_CODES[res.statusCode]}`; + reject(new ResponseError(this.reporter.lang('requestFailed', description), res.statusCode)); + + req.abort(); + }); + process(req, resolve, reject); } }