Skip to content

Commit

Permalink
fix: failed to execute json on response error in console on message send
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanmo226 committed Dec 30, 2024
1 parent e7636ca commit c03bea1
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 c03bea1

Please sign in to comment.