Skip to content

Commit

Permalink
Fix invalid afterResponse return check
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Aug 12, 2021
1 parent 15c30ee commit cbc8902
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/as-promise/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function asPromise<T>(firstRequest: Request): CancelableRequest<T
throw new RetryError(request);
});

if (!(is.object(response) && is.number(response.statusCode) && response.body)) {
if (!(is.object(response) && is.number(response.statusCode) && !is.nullOrUndefined(response.body))) {
throw new TypeError('The `afterResponse` hook returned an invalid value');
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1351,3 +1351,19 @@ test('can retry without an agent', withServer, async (t, server, got) => {
t.is(response.retryCount, 2);
t.is(counter, 1);
});

test('does not throw on empty body when running afterResponse hooks', withServer, async (t, server, got) => {
server.get('/', (_request, response) => {
response.end();
});

await t.notThrowsAsync(got('', {
hooks: {
afterResponse: [
response => {
return response;
}
]
}
}));
});

0 comments on commit cbc8902

Please sign in to comment.