-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
44 lines (36 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import consume from './consume'
import { ConsoleNeedLogin } from './const'
const defaultErrorCodes = {
[ConsoleNeedLogin]: {
enable: false
}
}
export default ({
errorCenter: {
enable = false,
errorCode,
errorCodes,
include,
exclude,
globalErrorCode,
getMessage,
} = {},
}) => {
if (process.env.NODE_ENV === 'development' && errorCode) {
console.error('[XConsole error-center]', '使用 errorCodes 来替代 errorCode(已废弃) '); // eslint-disable-line no-console
}
const lastErrorCodes = Object.assign({}, defaultErrorCodes, errorCodes || errorCode || {});
return {
onError(err) {
if (!enable) return false
if (process.env.NODE_ENV === 'development') {
console.error('[XConsole error-center]', err, err.response); // eslint-disable-line no-console
}
consume(err, lastErrorCodes, include, exclude, globalErrorCode, getMessage);
},
}
};
export const ErrorConsume = consume;
export const ErrorPrompt = (err, { errorConfig = {}, include, exclude, getMessage }) => {
consume(err, { ...errorConfig, type: 'prompt', enable: true }, include, exclude, getMessage);
};