Skip to content

Commit 024e9fe

Browse files
authored
Properly reports network errors (#6817)
* Properly reports network errors * Updates the changelog * Fixes flow
1 parent e987790 commit 024e9fe

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa
2828

2929
[#6712](https://github.com/yarnpkg/yarn/pull/6712) - [**Maël Nison**](https://twitter.com/arcanis)
3030

31+
- Properly reports the error codes when the npm registry throws 500's
32+
33+
[#6817](https://github.com/yarnpkg/yarn/pull/6817) - [**Maël Nison**](https://twitter.com/arcanis)
34+
3135
## 1.12.3
3236

3337
**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.

src/util/request-manager.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,19 @@ export default class RequestManager {
498498
req.on('data', queue.stillActive.bind(queue));
499499
}
500500

501-
if (params.process) {
502-
params.process(req, resolve, reject);
501+
const process = params.process;
502+
if (process) {
503+
req.on('response', res => {
504+
if (res.statusCode >= 200 && res.statusCode < 300) {
505+
return;
506+
}
507+
508+
const description = `${res.statusCode} ${http.STATUS_CODES[res.statusCode]}`;
509+
reject(new ResponseError(this.reporter.lang('requestFailed', description), res.statusCode));
510+
511+
req.abort();
512+
});
513+
process(req, resolve, reject);
503514
}
504515
}
505516

0 commit comments

Comments
 (0)