From 024e9febe853f3ff61d5ab9de7a7f83ea4bfdc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Fri, 14 Dec 2018 16:19:11 +0000 Subject: [PATCH] Properly reports network errors (#6817) * Properly reports network errors * Updates the changelog * Fixes flow --- CHANGELOG.md | 4 ++++ src/util/request-manager.js | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d38f2f3..f9d4f6a6 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 b886f7c4..3e944f6b 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); } }