Skip to content

Commit

Permalink
fix: Add try-catch block to prepare for JSON.parse errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
alstn2468 committed Jan 16, 2024
1 parent 38ac18b commit 8e20cf6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/core/Ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export class Ky {
if (options.parseJson) {
return options.parseJson(await response.text());
}

// If error causes when call JSON.parse
try {
return response[type]();

Check failure on line 106 in source/core/Ky.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Returning an awaited promise is required in this context.

Check failure on line 106 in source/core/Ky.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Returning an awaited promise is required in this context.
} catch {
return await response.text()

Check failure on line 108 in source/core/Ky.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Redundant use of `await` on a return value.

Check failure on line 108 in source/core/Ky.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Missing semicolon.

Check failure on line 108 in source/core/Ky.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Redundant use of `await` on a return value.

Check failure on line 108 in source/core/Ky.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Missing semicolon.
}
}

return response[type]();
Expand Down

0 comments on commit 8e20cf6

Please sign in to comment.