remove packages/errors changes
Signed-off-by: Aramis Sennyey <aramiss@spotify.com>
This commit is contained in:
@@ -34,7 +34,6 @@ export type ConsumedResponse = {
|
||||
values(): IterableIterator<string>;
|
||||
[Symbol.iterator](): Iterator<[string, string]>;
|
||||
};
|
||||
readonly bodyUsed: boolean;
|
||||
readonly ok: boolean;
|
||||
readonly redirected: boolean;
|
||||
readonly status: number;
|
||||
@@ -112,12 +111,6 @@ export class NotModifiedError extends CustomErrorBase {
|
||||
name: 'NotModifiedError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export function parseErrorResponseBody(
|
||||
response: ConsumedResponse,
|
||||
rawBody: string,
|
||||
): Promise<ErrorResponseBody>;
|
||||
|
||||
// @public
|
||||
export function parseErrorResponseBody(
|
||||
response: ConsumedResponse & {
|
||||
@@ -132,10 +125,8 @@ export class ResponseError extends Error {
|
||||
static fromResponse(
|
||||
response: ConsumedResponse & {
|
||||
text(): Promise<string>;
|
||||
bodyUsed: boolean;
|
||||
},
|
||||
): Promise<ResponseError>;
|
||||
readonly rawBody: string;
|
||||
readonly response: ConsumedResponse;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,11 +42,6 @@ export class ResponseError extends Error {
|
||||
*/
|
||||
readonly body: ErrorResponseBody;
|
||||
|
||||
/**
|
||||
* The unparsed possibly JSON error body. Will be set even if the returned error doesn't match {@link ErrorResponseBody}.
|
||||
*/
|
||||
readonly rawBody: string;
|
||||
|
||||
/**
|
||||
* The Error cause, as seen by the remote server. This is parsed out of the
|
||||
* JSON error body.
|
||||
@@ -66,20 +61,9 @@ export class ResponseError extends Error {
|
||||
* been consumed before.
|
||||
*/
|
||||
static async fromResponse(
|
||||
response: ConsumedResponse & { text(): Promise<string>; bodyUsed: boolean },
|
||||
response: ConsumedResponse & { text(): Promise<string> },
|
||||
): Promise<ResponseError> {
|
||||
let rawBody = '';
|
||||
try {
|
||||
rawBody = await response.text();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
const data = await parseErrorResponseBody(
|
||||
// TS isn't smart enough to know that this is done under the hood,
|
||||
response,
|
||||
rawBody,
|
||||
);
|
||||
const data = await parseErrorResponseBody(response);
|
||||
|
||||
const status = data.response.statusCode || response.status;
|
||||
const statusText = data.error.name || response.statusText;
|
||||
@@ -91,7 +75,6 @@ export class ResponseError extends Error {
|
||||
response,
|
||||
data,
|
||||
cause,
|
||||
rawBody,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -99,7 +82,6 @@ export class ResponseError extends Error {
|
||||
message: string;
|
||||
response: ConsumedResponse;
|
||||
data: ErrorResponseBody;
|
||||
rawBody: string;
|
||||
cause: Error;
|
||||
}) {
|
||||
super(props.message);
|
||||
@@ -107,6 +89,5 @@ export class ResponseError extends Error {
|
||||
this.response = props.response;
|
||||
this.body = props.data;
|
||||
this.cause = props.cause;
|
||||
this.rawBody = props.rawBody;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ export type ConsumedResponse = {
|
||||
values(): IterableIterator<string>;
|
||||
[Symbol.iterator](): Iterator<[string, string]>;
|
||||
};
|
||||
readonly bodyUsed: boolean;
|
||||
readonly ok: boolean;
|
||||
readonly redirected: boolean;
|
||||
readonly status: number;
|
||||
|
||||
@@ -41,19 +41,6 @@ export type ErrorResponseBody = {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Attempts to construct an ErrorResponseBody out of a failed server request.
|
||||
* Assumes that the response has already been checked to be not ok. This function
|
||||
* expects that rawBody is the body of the response and will not attempt to
|
||||
* parse the body from the response again.
|
||||
*
|
||||
* @public
|
||||
* @param response - The response of a failed request
|
||||
*/
|
||||
export async function parseErrorResponseBody(
|
||||
response: ConsumedResponse,
|
||||
rawBody: string,
|
||||
): Promise<ErrorResponseBody>;
|
||||
/**
|
||||
* Attempts to construct an ErrorResponseBody out of a failed server request.
|
||||
* Assumes that the response has already been checked to be not ok. This
|
||||
@@ -68,16 +55,9 @@ export async function parseErrorResponseBody(
|
||||
*/
|
||||
export async function parseErrorResponseBody(
|
||||
response: ConsumedResponse & { text(): Promise<string> },
|
||||
): Promise<ErrorResponseBody>;
|
||||
export async function parseErrorResponseBody(
|
||||
response: ConsumedResponse | (ConsumedResponse & { text(): Promise<string> }),
|
||||
rawBody?: string,
|
||||
): Promise<ErrorResponseBody> {
|
||||
try {
|
||||
const text =
|
||||
!response.bodyUsed && 'text' in response
|
||||
? await response.text()
|
||||
: rawBody;
|
||||
const text = await response.text();
|
||||
if (text) {
|
||||
if (
|
||||
response.headers.get('content-type')?.startsWith('application/json')
|
||||
|
||||
Reference in New Issue
Block a user