mirror of
https://github.com/renovatebot/renovate.git
synced 2024-12-22 13:38:32 +00:00
ce41717678
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
26 lines
739 B
TypeScript
26 lines
739 B
TypeScript
// Renovate issue: https://github.com/renovatebot/renovate/issues/12127
|
|
// Got issue: https://github.com/sindresorhus/got/issues/1489
|
|
// From here: https://github.com/sindresorhus/got/issues/1489#issuecomment-805485731
|
|
import type { Hooks, Response } from 'got';
|
|
|
|
export function isResponseOk(response: Response): boolean {
|
|
const { statusCode } = response;
|
|
const limitStatusCode = response.request.options.followRedirect ? 299 : 399;
|
|
|
|
return (
|
|
(statusCode >= 200 && statusCode <= limitStatusCode) || statusCode === 304
|
|
);
|
|
}
|
|
|
|
export function hook(response: Response): Response {
|
|
if (isResponseOk(response)) {
|
|
response.request.destroy();
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
export const hooks: Hooks = {
|
|
afterResponse: [hook],
|
|
};
|