Skip to content

Commit

Permalink
catch error in fall back to utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
archvlad committed Mar 3, 2024
1 parent 897f385 commit 42cd8ee
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions source/as-promise/index.ts
Expand Up @@ -7,7 +7,7 @@ import {
type RequestError,
} from '../core/errors.js';
import Request from '../core/index.js';
import {parseBody, isResponseOk, type Response} from '../core/response.js';
import {parseBody, isResponseOk, type Response, ParseError} from '../core/response.js';
import proxyEvents from '../core/utils/proxy-events.js';
import type Options from '../core/options.js';
import {CancelError, type CancelableRequest} from './types.js';
Expand Down Expand Up @@ -62,7 +62,12 @@ export default function asPromise<T>(firstRequest?: Request): CancelableRequest<
response.body = parseBody(response, options.responseType, options.parseJson, options.encoding);
} catch (error: any) {
// Fall back to `utf8`
response.body = response.rawBody.toString();
try {
response.body = response.rawBody.toString();

Check failure on line 66 in source/as-promise/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on macos-latest

Expected indentation of 7 tabs but found 28 spaces.
} catch (error) {

Check failure on line 67 in source/as-promise/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on macos-latest

Expected indentation of 6 tabs but found 24 spaces.
request._beforeError(new ParseError(error as Error, response));

Check failure on line 68 in source/as-promise/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on macos-latest

Expected indentation of 7 tabs but found 28 spaces.
return;

Check failure on line 69 in source/as-promise/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on macos-latest

Expected indentation of 7 tabs but found 28 spaces.
}

Check failure on line 70 in source/as-promise/index.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on macos-latest

Expected indentation of 6 tabs but found 24 spaces.

if (isResponseOk(response)) {
request._beforeError(error);
Expand Down

0 comments on commit 42cd8ee

Please sign in to comment.