Skip to content

Commit 2381926

Browse files
author
Ioan Moldovan
authored
fix: failed to execute json on response error in console on message send (#5892)
1 parent 5c2684e commit 2381926

File tree

1 file changed

+8
-1
lines changed
  • extension/js/common/api/shared

1 file changed

+8
-1
lines changed

extension/js/common/api/shared/api.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,14 @@ export class Api {
246246
} else if (resFmt === 'json') {
247247
try {
248248
const transformed = transformResponseWithProgressAndTimeout();
249-
return (await Promise.all([transformed.response.json(), transformed.pipe()]))[0] as FetchResult<T, RT>;
249+
return (
250+
await Promise.all([
251+
transformed.response.text().then(text => {
252+
return (text ? JSON.parse(text) : {}) as T; // Handle empty response body
253+
}),
254+
transformed.pipe(),
255+
])
256+
)[0] as FetchResult<T, RT>;
250257
} catch (e) {
251258
// handle empty response https://github.com/FlowCrypt/flowcrypt-browser/issues/5601
252259
if (e instanceof SyntaxError && (e.message === 'Unexpected end of JSON input' || e.message.startsWith('JSON.parse: unexpected end of data'))) {

0 commit comments

Comments
 (0)