2020-07-22 18:15:48 +00:00
|
|
|
// istanbul ignore file
|
2022-02-24 08:50:17 +00:00
|
|
|
import { RequestError as HttpError } from 'got';
|
2021-03-24 09:07:34 +00:00
|
|
|
import { parseUrl } from '../url';
|
2020-07-22 18:15:48 +00:00
|
|
|
|
2021-04-26 20:19:30 +00:00
|
|
|
// TODO: remove when code is refactored (#9651)
|
2020-07-22 18:15:48 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-29 04:39:27 +00:00
|
|
|
Object.defineProperty(HttpError.prototype, 'url', {
|
|
|
|
get: function url(this: HttpError) {
|
|
|
|
return this.response?.url;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-03-24 09:07:34 +00:00
|
|
|
Object.defineProperty(HttpError.prototype, 'host', {
|
|
|
|
get: function url(this: HttpError) {
|
2022-01-03 08:01:31 +00:00
|
|
|
const urlStr = this.response?.url;
|
|
|
|
const url = urlStr ? parseUrl(urlStr) : null;
|
|
|
|
return url?.host;
|
2021-03-24 09:07:34 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-22 18:15:48 +00:00
|
|
|
export type GotLegacyError<E = unknown, T = unknown> = HttpError & {
|
|
|
|
statusCode?: number;
|
|
|
|
body: {
|
|
|
|
message?: string;
|
|
|
|
errors?: E[];
|
|
|
|
};
|
|
|
|
headers?: Record<string, T>;
|
|
|
|
};
|