1.1.16 • Published 6 years ago
net4j-exception-plugin v1.1.16
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');
1.1.16
6 years ago
1.1.15
6 years ago
1.1.14
6 years ago
1.1.13
6 years ago
1.1.12
6 years ago
1.1.11
6 years ago
1.1.9
6 years ago
1.1.8
6 years ago
1.1.6
6 years ago
1.1.5
6 years ago
1.1.4
6 years ago
1.1.3
6 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago