exception的适配
This commit is contained in:
parent
3779a8c2de
commit
aad5f0c6f4
|
|
@ -1,7 +1,6 @@
|
|||
import {
|
||||
OakException,
|
||||
OakUnloggedInException,
|
||||
OakUserUnpermittedException,
|
||||
OakAttrNotNullException,
|
||||
OakInputIllegalException,
|
||||
} from 'oak-domain/lib/types/Exception';
|
||||
|
|
@ -10,47 +9,80 @@ import {
|
|||
} from '@project/types/Exception';
|
||||
import { FeatureDict } from '@project/features';
|
||||
import { AFD } from '@project/types/RuntimeCxt';
|
||||
import { OakApplicationLoadingException, OakHasToVerifyPassword, OakPasswordUnset, OakUserInfoLoadingException } from 'oak-general-business';
|
||||
// import { OakUserInfoLoadingException, OakApplicationLoadingException } from 'oak-general-business';
|
||||
|
||||
function showMessage(reason: OakException<any>, features: AFD, type?: MessageProps['type']) {
|
||||
const { message, _module, params} = reason;
|
||||
if (_module) {
|
||||
features.message.setMessage({
|
||||
content: features.locales.t(message, {
|
||||
['#oakModule']: _module,
|
||||
...(params || {}),
|
||||
}),
|
||||
type: type || 'error',
|
||||
});
|
||||
}
|
||||
else {
|
||||
features.message.setMessage({
|
||||
content: message,
|
||||
type: type || 'error',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function navigateTo(features: AFD, url: string, state?: Record<string, any>) {
|
||||
const { pathname } = features.navigator.getLocation();
|
||||
// 页面已经在本页的话,就不在跳转。这里要处理路径字符串的区别
|
||||
const s1 = pathname.split('/').filter(ele => !!ele);
|
||||
const s2 = url.split('/').filter(ele => !!ele);
|
||||
|
||||
if (s1.length === s2.length) {
|
||||
let same = true;
|
||||
s1.forEach(
|
||||
(ele, idx) => {
|
||||
if (ele !== s2[idx]) {
|
||||
same = false;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (same) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
features.navigator.navigateTo({ url }, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造backUrl
|
||||
* @param location
|
||||
* @param encode
|
||||
* @returns
|
||||
*/
|
||||
|
||||
export const handler = async (reason: any, features: AFD) => {
|
||||
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: features.locales.t(reason.message, {}),
|
||||
type: 'error',
|
||||
});
|
||||
} else if (reason instanceof OakAttrNotNullException) {
|
||||
features.message.setMessage({
|
||||
content: features.locales.t(reason.message, {}),
|
||||
type: 'error',
|
||||
});
|
||||
}/* else if (reason instanceof OakUserInfoLoadingException || reason instanceof OakApplicationLoadingException) {
|
||||
navigateTo(features, '/login');
|
||||
}
|
||||
else if (reason instanceof OakInputIllegalException) {
|
||||
showMessage(reason, features);
|
||||
}
|
||||
else if (reason instanceof OakHasToVerifyPassword) {
|
||||
navigateTo(features, '/my/password/verify');
|
||||
}
|
||||
else if (reason instanceof OakPasswordUnset) {
|
||||
navigateTo(features, 'my/password/update');
|
||||
}
|
||||
else if (reason instanceof OakAttrNotNullException) {
|
||||
showMessage(reason, features);
|
||||
} else if (reason instanceof OakUserInfoLoadingException || reason instanceof OakApplicationLoadingException) {
|
||||
// 暂不处理,在oak-general-business的page的生命周期里,等token加载完成了会刷新页面的
|
||||
console.warn(reason);
|
||||
} */else if (reason instanceof ExampleException) {
|
||||
// console.warn(reason);
|
||||
} else if (reason instanceof ExampleException) {
|
||||
console.log('在此处理ExampleException');
|
||||
} else {
|
||||
console.warn(reason);
|
||||
features.message.setMessage({
|
||||
content: features.locales.t(reason.message, {}),
|
||||
type: 'error',
|
||||
});
|
||||
showMessage(reason, features);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,9 @@
|
|||
import { OakException, OakUserException } from 'oak-domain/lib/types';
|
||||
import { EntityDict } from '@oak-app-domain';
|
||||
import { EntityDict } from '@project/oak-app-domain';
|
||||
import makeDepedentException from './DependentExceptions';
|
||||
|
||||
export class ExampleException extends OakException<EntityDict> {};
|
||||
|
||||
export class ConsoleModeIllegalException extends OakException<EntityDict> {};
|
||||
|
||||
export class ConsoleLoadingDataException extends OakException<EntityDict> {};
|
||||
|
||||
export class ExistsNewBidException extends OakUserException<EntityDict> {};
|
||||
|
||||
export function makeException(msg: string | object) {
|
||||
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
|
||||
|
||||
|
|
@ -18,10 +12,10 @@ export function makeException(msg: string | object) {
|
|||
return exception;
|
||||
}
|
||||
|
||||
const { name, message } = data;
|
||||
const { name, message, _module, params } = data;
|
||||
switch (name) {
|
||||
case 'ExampleException': {
|
||||
return new ExampleException(message);
|
||||
return new ExampleException(message, _module, params);
|
||||
}
|
||||
default: {
|
||||
throw new OakException(`不可解读的exception信息「${msg}」`);
|
||||
|
|
|
|||
Loading…
Reference in New Issue