diff --git a/examples/hooks.html b/examples/hooks.html
index 69c60fa..5b38f5a 100644
--- a/examples/hooks.html
+++ b/examples/hooks.html
@@ -58,7 +58,7 @@
}
)
.catch(
- (error) => console.error("post: ", error)
+ (error) => console.error("post: ", err.message, err.cause)
);
@@ -67,7 +67,7 @@
(res) => console.log(res)
)
.catch(
- (error) => console.error("page: ", error)
+ (error) => console.error("page: ", err.message, err.cause)
)
});
diff --git a/lib/useButter.js b/lib/useButter.js
index db308dd..b94cf23 100644
--- a/lib/useButter.js
+++ b/lib/useButter.js
@@ -123,18 +123,38 @@ export default function useButter(type, butterConfig) {
detail: errorDetail
} = await errorPayload.response.json();
+ const mappedParams = Object.fromEntries(
+ Object.entries(errorPayload.params)
+ .filter(([key]) => key !== 'auth_token')
+ )
+
+ const url = new URL(errorPayload.response.url)
+
+ // Remove auth_token from URL search params
+ url.searchParams.delete('auth_token');
+
+ const cause = {
+ data: errorDetail,
+ headers: errorPayload.response.headers,
+ status: errorPayload.response.status,
+ statusText: errorPayload.response.statusText,
+ config: errorPayload.config,
+ params: mappedParams,
+ type,
+ url
+ }
+
useOnError(
errorDetail,
- {
- config: errorPayload.config,
- params: errorPayload.params,
- type
- }
+ cause
);
return Promise.reject(
new Error(
- errorDetail
+ `${ errorDetail } (${ errorPayload.response.status })`,
+ {
+ cause
+ }
)
);
} else {
diff --git a/tests/basic.html b/tests/basic.html
index 1d03e38..664c7df 100644
--- a/tests/basic.html
+++ b/tests/basic.html
@@ -43,11 +43,11 @@
// add the catch to ensure you do not receive a "uncaught (in promise) warning"
.catch(
(err) => {
- console.error(err)
+ console.error(err.message, err.cause)
}
);
- butter.content.cancelRequest()
+ // butter.content.cancelRequest()
butter.post.list({
page: 1,
@@ -80,11 +80,11 @@
// add the catch to ensure you do not receive a "uncaught (in promise) warning"
.catch(
(err) => {
- console.error(err)
+ console.error(err.message, err.cause)
}
);
- butter.post.cancelRequest()
+ //butter.post.cancelRequest()
});