export async function handleError()

in src/push/request.ts [80:110]


export async function handleError(
  statusCode: number,
  url: string,
  body: Dispatcher.ResponseData['body'],
  extraMessage?: string
): Promise<Dispatcher.ResponseData['body']> {
  if (statusCode === 404) {
    throw formatNotFoundError(url, await body.text());
  } else if (!ok(statusCode)) {
    let parsed: APIError;
    try {
      const resp = await body.text();
      parsed = JSON.parse(resp) as APIError;
    } catch (e) {
      throw formatAPIError(
        statusCode,
        'unexpected error',
        e.message,
        extraMessage
      );
    }
    throw formatAPIError(
      statusCode,
      parsed.error,
      parsed.message,
      extraMessage
    );
  }

  return body;
}