@axmit/error-helper
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

error-helper

To start using:

yarn add @axmit/error-helper
import { errorMapper } from '@axmit/error-helper';

axios.interceptors.response.use(
  response => response.data,
  error => errorMapper
);
If you want show popup
import { errorMapper } from '@axmit/error-helper';
import { message } from 'antd';

...

axios.interceptors.response.use(
  response => response.data,
  error => errorMapper(error, { showError: message.error, defaultError: 'An error occurred, please try again later' })
);
Examples for different params
axios.interceptors.response.use(
  response => response.data,
  error => {
    const popupConfig = { showError: message.error, defaultError: EBaseErrorMessage.Default };
    const codesConfig = {
      withValidations: [...defaultCodesWithValidations, EErrorStatus.RetryWith],
      withPopupMessage: [EErrorStatus.PayloadTooLarge]
    };

    return errorMapper(error, popupConfig, codesConfig, t);
  }
);
Examples with antd4 forms (where error has type IError)
const LoginFormComponent: React.FC<AllProps> = props => {
    const { customerModel } = props;
    const { errors, params, data } = customerModel;
    const { fields } = useFormMapper(['name', 'email', 'password'], data, params, errors);
    ...

    return (
        <Form onFinish={login} fields={fields}>

Readme

Keywords

none

Package Sidebar

Install

npm i @axmit/error-helper

Weekly Downloads

2

Version

1.0.3

License

ISC

Unpacked Size

17.7 kB

Total Files

15

Last publish

Collaborators

  • axmit-engineers