Skip to content

Commit

Permalink
fix: failed to execute json on response error in console on message s…
Browse files Browse the repository at this point in the history
…end (#5892)
  • Loading branch information
ioanmo226 authored Jan 1, 2025
1 parent 5c2684e commit 2381926
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion extension/js/common/api/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,14 @@ export class Api {
} else if (resFmt === 'json') {
try {
const transformed = transformResponseWithProgressAndTimeout();
return (await Promise.all([transformed.response.json(), transformed.pipe()]))[0] as FetchResult<T, RT>;
return (
await Promise.all([
transformed.response.text().then(text => {
return (text ? JSON.parse(text) : {}) as T; // Handle empty response body
}),
transformed.pipe(),
])
)[0] as FetchResult<T, RT>;
} catch (e) {
// handle empty response https://github.com/FlowCrypt/flowcrypt-browser/issues/5601
if (e instanceof SyntaxError && (e.message === 'Unexpected end of JSON input' || e.message.startsWith('JSON.parse: unexpected end of data'))) {
Expand Down

0 comments on commit 2381926

Please sign in to comment.