0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/util/http/hooks.ts
Sergei Zharinov ce41717678
refactor(http): Fix coverage (#23004)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2023-06-28 11:55:26 +02:00

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],
};