@codebit-programando-solucoes/codebit-web-antd 1.1.20 → 1.1.21
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/components/index.d.ts +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useErrorMessage.d.ts +46 -0
- package/dist/hooks/useErrorModal.d.ts +27 -0
- package/dist/index.cjs +96 -45
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiError,
|
|
3
|
+
ApiNetworkError,
|
|
4
|
+
} from '@codebit-programando-solucoes/codebit-web';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Normalized status values used by UI components.
|
|
8
|
+
*
|
|
9
|
+
* - `'error'` – generic fallback status.
|
|
10
|
+
* - `403` – forbidden (often accompanied by a page‑reload action).
|
|
11
|
+
* - `404` – resource not found.
|
|
12
|
+
* - `500` – internal server error.
|
|
13
|
+
*/
|
|
14
|
+
export type ErrorStatus = 403 | 404 | 500 | 'error';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Shape of the object returned by `getErrorMessage`.
|
|
18
|
+
*
|
|
19
|
+
* @property {string} errorMessage - Human‑readable description of the error.
|
|
20
|
+
* @property {ErrorStatus} status - Normalized status for UI handling.
|
|
21
|
+
* @property {string} retryText - Text displayed on the retry button.
|
|
22
|
+
* @property {(() => void) | null} onRetryAction - Callback invoked when the user clicks the retry button, or `null` when no action is required.
|
|
23
|
+
*/
|
|
24
|
+
export interface ErrorMessage {
|
|
25
|
+
errorMessage: string;
|
|
26
|
+
status: ErrorStatus;
|
|
27
|
+
retryText: string;
|
|
28
|
+
onRetryAction: (() => void) | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Accepted error types for `getErrorMessage`.
|
|
33
|
+
*
|
|
34
|
+
* - Standard JavaScript `Error`.
|
|
35
|
+
* - `ApiError` and `ApiNetworkError` exported from the Codebit Web package.
|
|
36
|
+
*/
|
|
37
|
+
export type AcceptedError = Error | ApiError | ApiNetworkError;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Hook that returns a function to map an error object to an {@link ErrorMessage}.
|
|
41
|
+
*
|
|
42
|
+
* @returns {{ getErrorMessage: (error: AcceptedError) => ErrorMessage }}
|
|
43
|
+
*/
|
|
44
|
+
export function useErrorMessage(): {
|
|
45
|
+
getErrorMessage: (error: AcceptedError) => ErrorMessage;
|
|
46
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AcceptedError } from './useErrorMessage';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook that provides a function to display an error modal using Ant Design's `App` modal API. The hook integrates with Sentry for error reporting and with the library's
|
|
5
|
+
* translation utilities.
|
|
6
|
+
*
|
|
7
|
+
* @returns An object containing the `showErrorModal` function.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useErrorModal(): UseErrorModalReturn;
|
|
10
|
+
|
|
11
|
+
/** Shape of the object returned by {@link useErrorModal}. */
|
|
12
|
+
export interface UseErrorModalReturn {
|
|
13
|
+
/**
|
|
14
|
+
* Shows an error modal.
|
|
15
|
+
*
|
|
16
|
+
* @param error - The error to be displayed. It can be any object that extends the native `Error` type.
|
|
17
|
+
* @param title - Optional custom title for the modal. If omitted, a default translated title is used.
|
|
18
|
+
* @param closeButtonText - Optional custom text for the modal's close button.
|
|
19
|
+
* @param onClose - Optional callback executed when the modal is closed. If not provided, the retry action derived from the error message will be used.
|
|
20
|
+
*/
|
|
21
|
+
showErrorModal(
|
|
22
|
+
error: AcceptedError,
|
|
23
|
+
title?: string,
|
|
24
|
+
closeButtonText?: string,
|
|
25
|
+
onClose?: () => void,
|
|
26
|
+
): void;
|
|
27
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -297,12 +297,14 @@ var __webpack_exports__ = {};
|
|
|
297
297
|
LoggedMainContainer: ()=>LoggedMainContainer,
|
|
298
298
|
Login: ()=>Login,
|
|
299
299
|
CodebitThemeProvider: ()=>CodebitThemeProvider,
|
|
300
|
+
useErrorModal: ()=>useErrorModal,
|
|
300
301
|
ErrorRetry: ()=>ErrorRetry,
|
|
301
302
|
CodebitThemeContext: ()=>CodebitThemeContext,
|
|
302
303
|
CodebitConfigContext: ()=>CodebitConfigContext,
|
|
303
304
|
ListCard: ()=>ListCard,
|
|
304
305
|
ForgotPassword: ()=>ForgotPassword,
|
|
305
306
|
LoginContainer: ()=>LoginContainer,
|
|
307
|
+
useErrorMessage: ()=>useErrorMessage,
|
|
306
308
|
LocalLoginRecoveryPasswordResult: ()=>LocalLoginRecoveryPasswordResult,
|
|
307
309
|
FilterContainer: ()=>FilterContainer,
|
|
308
310
|
HandleError: ()=>HandleError,
|
|
@@ -424,7 +426,8 @@ var __webpack_exports__ = {};
|
|
|
424
426
|
genericMessage: 'Ocorreu um erro inesperado.',
|
|
425
427
|
backHome: 'Voltar para página inicial'
|
|
426
428
|
},
|
|
427
|
-
|
|
429
|
+
Error: {
|
|
430
|
+
errorTitle: 'Erro',
|
|
428
431
|
defaultError: 'Erro ao carregar',
|
|
429
432
|
retryButton: 'Tentar novamente',
|
|
430
433
|
reloadPageButton: 'Recarregar página',
|
|
@@ -525,7 +528,8 @@ var __webpack_exports__ = {};
|
|
|
525
528
|
genericMessage: 'An unexpected error occurred.',
|
|
526
529
|
backHome: 'Back to home'
|
|
527
530
|
},
|
|
528
|
-
|
|
531
|
+
Error: {
|
|
532
|
+
errorTitle: 'Error',
|
|
529
533
|
defaultError: 'Failed to load',
|
|
530
534
|
retryButton: 'Try again',
|
|
531
535
|
reloadPageButton: 'Reload page',
|
|
@@ -628,53 +632,69 @@ var __webpack_exports__ = {};
|
|
|
628
632
|
const useCodebitWebAntdTranslation = ()=>(0, external_react_i18next_namespaceObject.useTranslation)('codebitWebAntd', {
|
|
629
633
|
i18n: i18n
|
|
630
634
|
});
|
|
635
|
+
function useErrorMessage() {
|
|
636
|
+
const { t } = useCodebitWebAntdTranslation();
|
|
637
|
+
const getErrorMessage = (error)=>{
|
|
638
|
+
let status = 'error';
|
|
639
|
+
const responseStatus = error?.response?.status || null;
|
|
640
|
+
let errorMessage = t('Error.defaultError');
|
|
641
|
+
let retryText = t('Error.retryButton');
|
|
642
|
+
let onRetryAction = null;
|
|
643
|
+
if (error?.errorCode) switch(error.errorCode){
|
|
644
|
+
case codebit_web_namespaceObject.ErrorCode.ERR_NETWORK:
|
|
645
|
+
errorMessage = t('Error.networkError');
|
|
646
|
+
break;
|
|
647
|
+
case codebit_web_namespaceObject.ErrorCode.ERR_TIMEOUT:
|
|
648
|
+
errorMessage = t('Error.timeoutError');
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
else if (responseStatus) switch(responseStatus){
|
|
652
|
+
case 400:
|
|
653
|
+
errorMessage = t('Error.badRequestError');
|
|
654
|
+
break;
|
|
655
|
+
case 403:
|
|
656
|
+
errorMessage = t('Error.forbiddenError');
|
|
657
|
+
retryText = t('Error.reloadPageButton');
|
|
658
|
+
status = 403;
|
|
659
|
+
onRetryAction = ()=>{
|
|
660
|
+
globalThis.location.reload();
|
|
661
|
+
};
|
|
662
|
+
break;
|
|
663
|
+
case 404:
|
|
664
|
+
errorMessage = t('Error.notFoundError');
|
|
665
|
+
status = 404;
|
|
666
|
+
break;
|
|
667
|
+
case 500:
|
|
668
|
+
errorMessage = t('Error.internalServerError');
|
|
669
|
+
status = 500;
|
|
670
|
+
break;
|
|
671
|
+
case 401:
|
|
672
|
+
errorMessage = t('Error.sessionExpiredError');
|
|
673
|
+
retryText = t('Error.reloadPageButton');
|
|
674
|
+
onRetryAction = ()=>{
|
|
675
|
+
globalThis.location.reload();
|
|
676
|
+
};
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
errorMessage,
|
|
681
|
+
status,
|
|
682
|
+
retryText,
|
|
683
|
+
onRetryAction
|
|
684
|
+
};
|
|
685
|
+
};
|
|
686
|
+
return {
|
|
687
|
+
getErrorMessage
|
|
688
|
+
};
|
|
689
|
+
}
|
|
631
690
|
const ErrorRetry_logger = new codebit_web_namespaceObject.Logger('ErrorRetry');
|
|
632
691
|
function ErrorRetry({ error, onRetry }) {
|
|
633
|
-
const { t } = useCodebitWebAntdTranslation();
|
|
634
692
|
if (error && error instanceof Error) {
|
|
635
693
|
ErrorRetry_logger.error('Fail to load.', error);
|
|
636
694
|
react_namespaceObject.captureException(error);
|
|
637
695
|
}
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
let retryText = t('ErrorRetry.retryButton');
|
|
641
|
-
let status = 'error';
|
|
642
|
-
if (error?.errorCode) switch(error.errorCode){
|
|
643
|
-
case codebit_web_namespaceObject.ErrorCode.ERR_NETWORK:
|
|
644
|
-
errorMessage = t('ErrorRetry.networkError');
|
|
645
|
-
break;
|
|
646
|
-
case codebit_web_namespaceObject.ErrorCode.ERR_TIMEOUT:
|
|
647
|
-
errorMessage = t('ErrorRetry.timeoutError');
|
|
648
|
-
break;
|
|
649
|
-
}
|
|
650
|
-
else if (responseStatus) switch(responseStatus){
|
|
651
|
-
case 400:
|
|
652
|
-
errorMessage = t('ErrorRetry.badRequestError');
|
|
653
|
-
break;
|
|
654
|
-
case 403:
|
|
655
|
-
errorMessage = t('ErrorRetry.forbiddenError');
|
|
656
|
-
retryText = t('ErrorRetry.reloadPageButton');
|
|
657
|
-
onRetry = ()=>{
|
|
658
|
-
globalThis.location.reload();
|
|
659
|
-
};
|
|
660
|
-
status = 403;
|
|
661
|
-
break;
|
|
662
|
-
case 404:
|
|
663
|
-
errorMessage = t('ErrorRetry.notFoundError');
|
|
664
|
-
status = 404;
|
|
665
|
-
break;
|
|
666
|
-
case 500:
|
|
667
|
-
errorMessage = t('ErrorRetry.internalServerError');
|
|
668
|
-
status = 500;
|
|
669
|
-
break;
|
|
670
|
-
case 401:
|
|
671
|
-
errorMessage = t('ErrorRetry.sessionExpiredError');
|
|
672
|
-
retryText = t('ErrorRetry.reloadPageButton');
|
|
673
|
-
onRetry = ()=>{
|
|
674
|
-
globalThis.location.reload();
|
|
675
|
-
};
|
|
676
|
-
break;
|
|
677
|
-
}
|
|
696
|
+
const { getErrorMessage } = useErrorMessage();
|
|
697
|
+
const { status, errorMessage, retryText, onRetryAction } = getErrorMessage(error);
|
|
678
698
|
return /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Card, {
|
|
679
699
|
children: /*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Result, {
|
|
680
700
|
status: status,
|
|
@@ -682,7 +702,7 @@ var __webpack_exports__ = {};
|
|
|
682
702
|
extra: [
|
|
683
703
|
/*#__PURE__*/ (0, jsx_runtime.jsx)(external_antd_namespaceObject.Button, {
|
|
684
704
|
type: 'primary',
|
|
685
|
-
onClick: onRetry,
|
|
705
|
+
onClick: onRetryAction ?? onRetry,
|
|
686
706
|
icon: /*#__PURE__*/ (0, jsx_runtime.jsx)(icons_namespaceObject.ReloadOutlined, {}),
|
|
687
707
|
children: retryText
|
|
688
708
|
}, 'retry')
|
|
@@ -1679,6 +1699,33 @@ var __webpack_exports__ = {};
|
|
|
1679
1699
|
navigateToLogin: external_prop_types_default().func,
|
|
1680
1700
|
submitRecoveryPassword: external_prop_types_default().func.isRequired
|
|
1681
1701
|
};
|
|
1702
|
+
const useErrorModal_logger = new codebit_web_namespaceObject.Logger('useErrorModal');
|
|
1703
|
+
function useErrorModal() {
|
|
1704
|
+
const { modal } = external_antd_namespaceObject.App.useApp();
|
|
1705
|
+
const { getErrorMessage } = useErrorMessage();
|
|
1706
|
+
const { t } = useCodebitWebAntdTranslation();
|
|
1707
|
+
const showErrorModal = (error, title, closeButtonText, onClose)=>{
|
|
1708
|
+
if (error && error instanceof Error) {
|
|
1709
|
+
useErrorModal_logger.error('Fail to load.', error);
|
|
1710
|
+
react_namespaceObject.captureException(error);
|
|
1711
|
+
}
|
|
1712
|
+
const { errorMessage, retryText, onRetryAction } = getErrorMessage(error);
|
|
1713
|
+
if (error && error instanceof Error) {
|
|
1714
|
+
useErrorModal_logger.error(error);
|
|
1715
|
+
react_namespaceObject.captureException(error);
|
|
1716
|
+
}
|
|
1717
|
+
onClose = onClose ?? onRetryAction;
|
|
1718
|
+
modal.error({
|
|
1719
|
+
title: title || t('Error.errorTitle'),
|
|
1720
|
+
content: errorMessage + '.',
|
|
1721
|
+
afterClose: onClose,
|
|
1722
|
+
okText: closeButtonText || (onClose ? retryText : t('Common.close'))
|
|
1723
|
+
});
|
|
1724
|
+
};
|
|
1725
|
+
return {
|
|
1726
|
+
showErrorModal
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1682
1729
|
})();
|
|
1683
1730
|
exports.CodebitConfigContext = __webpack_exports__.CodebitConfigContext;
|
|
1684
1731
|
exports.CodebitConfigProvider = __webpack_exports__.CodebitConfigProvider;
|
|
@@ -1697,6 +1744,8 @@ exports.Login = __webpack_exports__.Login;
|
|
|
1697
1744
|
exports.LoginContainer = __webpack_exports__.LoginContainer;
|
|
1698
1745
|
exports.TableContainer = __webpack_exports__.TableContainer;
|
|
1699
1746
|
exports.ThemeToggle = __webpack_exports__.ThemeToggle;
|
|
1747
|
+
exports.useErrorMessage = __webpack_exports__.useErrorMessage;
|
|
1748
|
+
exports.useErrorModal = __webpack_exports__.useErrorModal;
|
|
1700
1749
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
1701
1750
|
"CodebitConfigContext",
|
|
1702
1751
|
"CodebitConfigProvider",
|
|
@@ -1714,7 +1763,9 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
1714
1763
|
"Login",
|
|
1715
1764
|
"LoginContainer",
|
|
1716
1765
|
"TableContainer",
|
|
1717
|
-
"ThemeToggle"
|
|
1766
|
+
"ThemeToggle",
|
|
1767
|
+
"useErrorMessage",
|
|
1768
|
+
"useErrorModal"
|
|
1718
1769
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
1719
1770
|
Object.defineProperty(exports, '__esModule', {
|
|
1720
1771
|
value: true
|
package/dist/index.d.ts
CHANGED