Exception
This commit is contained in:
parent
31e0327a41
commit
164ae2a4a6
|
|
@ -55,6 +55,7 @@ function makeIntrinsicWatchers(schema) {
|
||||||
const watchers = [];
|
const watchers = [];
|
||||||
for (const entity in schema) {
|
for (const entity in schema) {
|
||||||
const { attributes } = schema[entity];
|
const { attributes } = schema[entity];
|
||||||
|
const now = Date.now();
|
||||||
const { expiresAt, expired } = attributes;
|
const { expiresAt, expired } = attributes;
|
||||||
if (expiresAt && expiresAt.type === 'datetime' && expired && expired.type === 'boolean') {
|
if (expiresAt && expiresAt.type === 'datetime' && expired && expired.type === 'boolean') {
|
||||||
// 如果有定义expiresAt和expired,则自动生成一个检查的watcher
|
// 如果有定义expiresAt和expired,则自动生成一个检查的watcher
|
||||||
|
|
@ -62,7 +63,6 @@ function makeIntrinsicWatchers(schema) {
|
||||||
entity,
|
entity,
|
||||||
name: `对象${entity}上的过期自动watcher`,
|
name: `对象${entity}上的过期自动watcher`,
|
||||||
filter: async () => {
|
filter: async () => {
|
||||||
const now = Date.now();
|
|
||||||
return {
|
return {
|
||||||
expired: false,
|
expired: false,
|
||||||
expiresAt: {
|
expiresAt: {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { EntityDict, OpRecord } from "./Entity";
|
import { EntityDict, OpRecord } from "./Entity";
|
||||||
export declare class OakException extends Error {
|
export declare class OakException extends Error {
|
||||||
|
toString(): string;
|
||||||
}
|
}
|
||||||
export declare class OakUserException extends OakException {
|
export declare class OakUserException extends OakException {
|
||||||
}
|
}
|
||||||
|
|
@ -11,6 +12,7 @@ export declare class OakRowInconsistencyException<ED extends EntityDict> extends
|
||||||
private data?;
|
private data?;
|
||||||
constructor(data?: OpRecord<ED>, message?: string);
|
constructor(data?: OpRecord<ED>, message?: string);
|
||||||
getData(): OpRecord<ED> | undefined;
|
getData(): OpRecord<ED> | undefined;
|
||||||
|
toString(): string;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 当输入的数据非法时抛此异常,attributes表示非法的属性
|
* 当输入的数据非法时抛此异常,attributes表示非法的属性
|
||||||
|
|
@ -20,6 +22,7 @@ export declare class OakInputIllegalException extends OakUserException {
|
||||||
constructor(attributes: string[], message?: string);
|
constructor(attributes: string[], message?: string);
|
||||||
getAttributes(): string[];
|
getAttributes(): string[];
|
||||||
addAttributesPrefix(prefix: string): void;
|
addAttributesPrefix(prefix: string): void;
|
||||||
|
toString(): string;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 用户权限不够时抛的异常
|
* 用户权限不够时抛的异常
|
||||||
|
|
@ -33,4 +36,10 @@ export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyo
|
||||||
private data;
|
private data;
|
||||||
constructor(data: ED[T]['OpSchema'], message?: string);
|
constructor(data: ED[T]['OpSchema'], message?: string);
|
||||||
getData(): ED[T]["OpSchema"];
|
getData(): ED[T]["OpSchema"];
|
||||||
|
toString(): string;
|
||||||
}
|
}
|
||||||
|
export declare function makeException(data: {
|
||||||
|
name: string;
|
||||||
|
message?: string;
|
||||||
|
[A: string]: any;
|
||||||
|
}): OakException | undefined;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.OakCongruentRowExists = exports.OakUserUnpermittedException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakException = void 0;
|
exports.makeException = exports.OakCongruentRowExists = exports.OakUserUnpermittedException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakException = void 0;
|
||||||
class OakException extends Error {
|
class OakException extends Error {
|
||||||
|
toString() {
|
||||||
|
return JSON.stringify({
|
||||||
|
name: this.name,
|
||||||
|
message: this.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.OakException = OakException;
|
exports.OakException = OakException;
|
||||||
class OakUserException extends OakException {
|
class OakUserException extends OakException {
|
||||||
|
|
@ -22,6 +28,13 @@ class OakRowInconsistencyException extends OakUserException {
|
||||||
getData() {
|
getData() {
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
toString() {
|
||||||
|
return JSON.stringify({
|
||||||
|
name: this.name,
|
||||||
|
message: this.message,
|
||||||
|
data: this.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.OakRowInconsistencyException = OakRowInconsistencyException;
|
exports.OakRowInconsistencyException = OakRowInconsistencyException;
|
||||||
;
|
;
|
||||||
|
|
@ -40,6 +53,13 @@ class OakInputIllegalException extends OakUserException {
|
||||||
addAttributesPrefix(prefix) {
|
addAttributesPrefix(prefix) {
|
||||||
this.attributes = this.attributes.map(ele => `${prefix}.${ele}`);
|
this.attributes = this.attributes.map(ele => `${prefix}.${ele}`);
|
||||||
}
|
}
|
||||||
|
toString() {
|
||||||
|
return JSON.stringify({
|
||||||
|
name: this.name,
|
||||||
|
message: this.message,
|
||||||
|
attributes: this.attributes,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.OakInputIllegalException = OakInputIllegalException;
|
exports.OakInputIllegalException = OakInputIllegalException;
|
||||||
;
|
;
|
||||||
|
|
@ -62,5 +82,38 @@ class OakCongruentRowExists extends OakUserException {
|
||||||
getData() {
|
getData() {
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
toString() {
|
||||||
|
return JSON.stringify({
|
||||||
|
name: this.name,
|
||||||
|
message: this.message,
|
||||||
|
data: this.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.OakCongruentRowExists = OakCongruentRowExists;
|
exports.OakCongruentRowExists = OakCongruentRowExists;
|
||||||
|
function makeException(data) {
|
||||||
|
const { name } = data;
|
||||||
|
switch (name) {
|
||||||
|
case OakException.name: {
|
||||||
|
return new OakException(data.message);
|
||||||
|
}
|
||||||
|
case OakUserException.name: {
|
||||||
|
return new OakUserException(data.message);
|
||||||
|
}
|
||||||
|
case OakRowInconsistencyException.name: {
|
||||||
|
return new OakRowInconsistencyException(data.data, data.message);
|
||||||
|
}
|
||||||
|
case OakInputIllegalException.name: {
|
||||||
|
return new OakInputIllegalException(data.attributes, data.message);
|
||||||
|
}
|
||||||
|
case OakUserUnpermittedException.name: {
|
||||||
|
return new OakUserUnpermittedException(data.message);
|
||||||
|
}
|
||||||
|
case OakCongruentRowExists.name: {
|
||||||
|
return new OakCongruentRowExists(data.data, data.message);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.makeException = makeException;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ type SelectOption = {
|
||||||
|
|
||||||
export type OperateParams = {
|
export type OperateParams = {
|
||||||
notCollect?: boolean;
|
notCollect?: boolean;
|
||||||
obscure?: boolean; // 如果为置为true,则在filter过程中因数据不完整而不能判断为真的时候都假设为真(前端缓存)
|
obscure?: boolean; // 如果为置为true,则在filter过程中因数据不完整而不能判断为真的时候都假设为真(前端缓存专用)
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FormUpdateData<SH extends GeneralEntityShape> = Partial<Omit<SH, InstinctiveAttributes>>;
|
export type FormUpdateData<SH extends GeneralEntityShape> = Partial<Omit<SH, InstinctiveAttributes>>;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
import { EntityDict, OpRecord } from "./Entity";
|
import { EntityDict, OpRecord } from "./Entity";
|
||||||
|
|
||||||
export class OakException extends Error {
|
export class OakException extends Error {
|
||||||
|
toString() {
|
||||||
|
return JSON.stringify({
|
||||||
|
name: this.name,
|
||||||
|
message: this.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OakUserException extends OakException {
|
export class OakUserException extends OakException {
|
||||||
|
|
@ -22,6 +28,14 @@ export class OakUserException extends OakException {
|
||||||
getData() {
|
getData() {
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return JSON.stringify({
|
||||||
|
name: this.name,
|
||||||
|
message: this.message,
|
||||||
|
data: this.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,6 +57,14 @@ export class OakInputIllegalException extends OakUserException {
|
||||||
ele => `${prefix}.${ele}`
|
ele => `${prefix}.${ele}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return JSON.stringify({
|
||||||
|
name: this.name,
|
||||||
|
message: this.message,
|
||||||
|
attributes: this.attributes,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -65,4 +87,42 @@ export class OakCongruentRowExists<ED extends EntityDict, T extends keyof ED> ex
|
||||||
getData() {
|
getData() {
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return JSON.stringify({
|
||||||
|
name: this.name,
|
||||||
|
message: this.message,
|
||||||
|
data: this.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeException(data: {
|
||||||
|
name: string;
|
||||||
|
message?: string;
|
||||||
|
[A: string]: any;
|
||||||
|
}) {
|
||||||
|
const { name } = data;
|
||||||
|
switch (name) {
|
||||||
|
case OakException.name: {
|
||||||
|
return new OakException(data.message);
|
||||||
|
}
|
||||||
|
case OakUserException.name: {
|
||||||
|
return new OakUserException(data.message);
|
||||||
|
}
|
||||||
|
case OakRowInconsistencyException.name: {
|
||||||
|
return new OakRowInconsistencyException(data.data, data.message);
|
||||||
|
}
|
||||||
|
case OakInputIllegalException.name: {
|
||||||
|
return new OakInputIllegalException(data.attributes, data.message);
|
||||||
|
}
|
||||||
|
case OakUserUnpermittedException.name: {
|
||||||
|
return new OakUserUnpermittedException(data.message);
|
||||||
|
}
|
||||||
|
case OakCongruentRowExists.name: {
|
||||||
|
return new OakCongruentRowExists(data.data, data.message);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue