Skip to content

Commit

Permalink
feat: 🎸 http.request returns error for rejected promise
Browse files Browse the repository at this point in the history
  • Loading branch information
mjancarik committed Sep 13, 2024
1 parent 833db58 commit b1427af
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/plugin-http-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ function httpClientAPI() {
);

if (!response.ok) {
return Promise.reject({ request, response });
const error = new Error(`${response.statusText}: ${request.url}`, {
cause: { request, response },
});
// keep compatablity
error.request = request;
error.response = response;

return Promise.reject(error);
}

return { request, response };
Expand All @@ -94,10 +101,10 @@ async function runTransformers(widget, transformers, method, ...rest) {

function getFetchAPI() {
if (typeof window === 'undefined') {
return global.fetch;
return global?.fetch;
}

return window.fetch.bind(window);
return window?.fetch?.bind?.(window);
}

export function transformQuery() {
Expand Down

0 comments on commit b1427af

Please sign in to comment.