# net4j-exception-plugin

> Handle every request when exception

Latest version **1.1.16** (published 2019-11-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install net4j-exception-plugin
pnpm add net4j-exception-plugin
yarn add net4j-exception-plugin
bun add net4j-exception-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.16 |
| Published | 2019-11-08 |
| First published | 2019-03-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | forthedamn |
| Maintainers | forthedamn |
| Keywords | http |

## Links

- npm: https://www.npmjs.com/package/net4j-exception-plugin
- npm.io page: https://npm.io/package/net4j-exception-plugin

## Dependencies (1)

- [net4j](https://npm.io/package/net4j.md) latest

## Recent versions

- 1.1.16 (latest) — 2019-11-08
- 1.1.15 — 2019-07-10
- 1.1.14 — 2019-07-04
- 1.1.13 — 2019-07-03
- 1.1.12 — 2019-06-20
- 1.1.11 — 2019-04-24
- 1.1.9 — 2019-04-23
- 1.1.8 — 2019-04-23
- 1.1.6 — 2019-04-08
- 1.1.5 — 2019-04-08
- 1.1.4 — 2019-03-26
- 1.1.3 — 2019-03-26
- 1.1.2 — 2019-03-25
- 1.1.1 — 2019-03-19
- 1.1.0 — 2019-03-18
- … 6 more at https://npm.io/package/net4j-exception-plugin/versions

## README

# net4j-exception-plugin

Easily to set tip when request get exception.

```
import Net from 'net4j';
import { Modal } from 'antd';
import NetException, { PluginConfig } from 'net4j-exception-plugin';

// Merge plugin config to net4j config,then you can use it in every requst in net4j
declare module 'net4j' {
  interface Config extends PluginConfig {}
}

// Code to message
// Code comes from http status,response result.code,promise reject error.code
const codeMsgMap = (code) => {
  const map = {
    404: 'page not found',
    403: function() {
      // In this time, tipsComponent will not show.
      link.to('/login');
    },
    5400: '商品名重复'
  };
  return map[code];
}

const net = new Net({
  plugins: [
    otherPlugins...,
    // Exception plugin should be placed last
    new NetException({
      tipsComponent: (code, text) => {
          return Modal.error({
            title: code,
            content: text,
          }),
      defaultExceptionText: '请求异常，请重试', // Default is 'fail'
      codeMsgMap,
    }),
  ]
});

// When api/goods get exception，error modal will display;
await net.get('api/goods');
```

---
_Source: https://npm.io/package/net4j-exception-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
