@hexdspace/react 0.0.23 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -522,7 +522,11 @@ var FetchHttpClient = class {
|
|
|
522
522
|
signal: config?.signal
|
|
523
523
|
});
|
|
524
524
|
const data = await (res.headers.get("content-type")?.includes("application/json") ? res.json() : res.text());
|
|
525
|
-
if (!res.ok)
|
|
525
|
+
if (!res.ok) {
|
|
526
|
+
const errorResponse = data;
|
|
527
|
+
const message = errorResponse?.error ?? res.statusText;
|
|
528
|
+
throw new HttpError(message, res.status, errorResponse);
|
|
529
|
+
}
|
|
526
530
|
return {
|
|
527
531
|
data,
|
|
528
532
|
status: res.status,
|
|
@@ -856,15 +860,21 @@ function dispatchLoginResult(res, dispatch) {
|
|
|
856
860
|
if (res.ok) {
|
|
857
861
|
dispatch({ type: "COMPLETE", user: res.value });
|
|
858
862
|
} else {
|
|
859
|
-
dispatch({ type: "FAILED", error: res.error
|
|
863
|
+
dispatch({ type: "FAILED", error: getErrorMessage(res.error) });
|
|
860
864
|
}
|
|
861
865
|
}
|
|
862
866
|
function dispatchRegisterResult(res, dispatch) {
|
|
863
867
|
if (res.ok) {
|
|
864
868
|
dispatch({ type: "SUCCESS", message: res.value.message });
|
|
865
869
|
} else {
|
|
866
|
-
dispatch({ type: "FAILED", error: res.error
|
|
870
|
+
dispatch({ type: "FAILED", error: getErrorMessage(res.error) });
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
function getErrorMessage(error) {
|
|
874
|
+
if (error instanceof HttpError) {
|
|
875
|
+
return error.response.error ?? error.message;
|
|
867
876
|
}
|
|
877
|
+
return error.message;
|
|
868
878
|
}
|
|
869
879
|
|
|
870
880
|
// src/feature/auth/interface/web/react/hook/useAuthedUser.tsx
|