0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/util/http/legacy.ts
MaronHatoum b121deb969
refactor(util/http): move interfaces from index.ts to types.ts (#14335)
* refactor:util/http move interfaces and types from index.ts to types.ts

* refactor:reorder imports

* refactor:move HttpError from type.ts to index.ts

* refactor:change imports after moving HttpError from type.ts to index.ts

* refactor:revert white spaces

* refactor:revert moving httpError from types.ts to index.ts

* refactor: moving httpError from types.ts to index.ts

* refactor: change import

* refactor: change import

* refactor: change import

* refactor: fix circular dependencies (lint build)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2022-02-24 08:50:17 +00:00

52 lines
1.2 KiB
TypeScript

// istanbul ignore file
import { RequestError as HttpError } from 'got';
import { parseUrl } from '../url';
// TODO: remove when code is refactored (#9651)
Object.defineProperty(HttpError.prototype, 'statusCode', {
get: function statusCode(this: HttpError) {
return this.response?.statusCode;
},
});
Object.defineProperty(HttpError.prototype, 'body', {
get: function body(this: HttpError): unknown {
return this.response?.body;
},
set: function body(this: HttpError, value: unknown): void {
if (this.response) {
this.response.body = value;
}
},
});
Object.defineProperty(HttpError.prototype, 'headers', {
get: function headers(this: HttpError) {
return this.response?.headers;
},
});
Object.defineProperty(HttpError.prototype, 'url', {
get: function url(this: HttpError) {
return this.response?.url;
},
});
Object.defineProperty(HttpError.prototype, 'host', {
get: function url(this: HttpError) {
const urlStr = this.response?.url;
const url = urlStr ? parseUrl(urlStr) : null;
return url?.host;
},
});
export type GotLegacyError<E = unknown, T = unknown> = HttpError & {
statusCode?: number;
body: {
message?: string;
errors?: E[];
};
headers?: Record<string, T>;
};