Skip to content

Commit

Permalink
fix: 204 http response (#6266)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-zurek authored Mar 20, 2023
1 parent 76202ca commit 771f6ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,13 @@ var nativeBridge = (function (exports) {
data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
headers: headers,
});
const data = typeof nativeResponse.data === 'string'
let data = typeof nativeResponse.data === 'string'
? nativeResponse.data
: JSON.stringify(nativeResponse.data);
// use null data for 204 No Content HTTP response
if (nativeResponse.status === 204) {
data = null;
}
// intercept & parse response before returning
const response = new Response(data, {
headers: nativeResponse.headers,
Expand Down
8 changes: 7 additions & 1 deletion core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,16 @@ const initBridge = (w: any): void => {
},
);

const data =
let data =
typeof nativeResponse.data === 'string'
? nativeResponse.data
: JSON.stringify(nativeResponse.data);

// use null data for 204 No Content HTTP response
if (nativeResponse.status === 204) {
data = null;
}

// intercept & parse response before returning
const response = new Response(data, {
headers: nativeResponse.headers,
Expand Down
6 changes: 5 additions & 1 deletion ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,13 @@ var nativeBridge = (function (exports) {
data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
headers: headers,
});
const data = typeof nativeResponse.data === 'string'
let data = typeof nativeResponse.data === 'string'
? nativeResponse.data
: JSON.stringify(nativeResponse.data);
// use null data for 204 No Content HTTP response
if (nativeResponse.status === 204) {
data = null;
}
// intercept & parse response before returning
const response = new Response(data, {
headers: nativeResponse.headers,
Expand Down

0 comments on commit 771f6ce

Please sign in to comment.