oak-pay-business/es/exceptionHandler.js

48 lines
1.4 KiB
JavaScript

import { OakException, OakUnloggedInException, OakAttrNotNullException, OakInputIllegalException, } from 'oak-domain/lib/types/Exception';
import { ExampleException, } from './types/Exception';
/**
* 构造backUrl
* @param location
* @param encode
* @returns
*/
export const handler = async (reason, features) => {
if (reason instanceof OakException) {
if (reason instanceof OakUnloggedInException) {
// await features.token.logout();
features.navigator.navigateTo({
url: '/login',
}, { isGoBack: true }, true);
}
else if (reason instanceof OakInputIllegalException) {
features.message.setMessage({
content: reason.message,
type: 'error',
});
}
else if (reason instanceof OakAttrNotNullException) {
features.message.setMessage({
content: reason.message,
type: 'error',
});
}
else if (reason instanceof ExampleException) {
console.log('在此处理ExampleException');
}
else {
console.warn(reason);
features.message.setMessage({
content: reason.message,
type: 'error',
});
}
return true;
}
console.error(reason);
features.message.setMessage({
content: reason.message,
type: 'error',
});
return false;
};