Skip to content

Commit

Permalink
Add missing ECONNRESET code to an abort error
Browse files Browse the repository at this point in the history
Fixes #1311
  • Loading branch information
szmarczak committed Jul 3, 2020
1 parent 728aef9 commit d325d35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,8 @@ export default class Request extends Duplex implements RequestEvents<Request> {
response.once('aborted', () => {
this._beforeError(new ReadError({
name: 'Error',
message: 'The server aborted pending request'
message: 'The server aborted pending request',
code: 'ECONNRESET'
}, this));
});

Expand Down
6 changes: 4 additions & 2 deletions test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {isIPv4, isIPv6} from 'net';
import nock = require('nock');
import getStream = require('get-stream');
import pEvent from 'p-event';
import got, {HTTPError, UnsupportedProtocolError, CancelableRequest} from '../source';
import got, {HTTPError, UnsupportedProtocolError, CancelableRequest, ReadError} from '../source';
import withServer from './helpers/with-server';
import os = require('os');

Expand Down Expand Up @@ -222,9 +222,11 @@ test('throws an error if the server aborted the request', withServer, async (t,
});
});

await t.throwsAsync(got(''), {
const error = await t.throwsAsync<ReadError>(got(''), {
message: 'The server aborted pending request'
});

t.truthy(error.response.retryCount);
});

test('statusMessage fallback', async t => {
Expand Down

0 comments on commit d325d35

Please sign in to comment.