Typescript:express-validator 中 'throw' 函数的错误类型是什么?
Typescript: What is the error type of 'throw' function in express-validator?
我需要检测这个函数抛出的错误类型:
validationResult(req).throw()
这是抛出函数的定义:
throw() {
if (!this.isEmpty()) {
throw Object.assign(new Error(), utils_1.bindAll(this));
}
}
这是 utils_1.bindAll 函数:
exports.bindAll = (object) => {
const protoKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(object));
protoKeys.forEach(key => {
const maybeFn = object[key];
if (typeof maybeFn === 'function' && key !== 'constructor') {
object[key] = maybeFn.bind(object);
}
});
return object;
};
似乎 throw() 函数不会抛出特定类型的错误,但我需要以某种方式找到它,因为我想以特定方式处理 express-validator 错误。
根据express-validators的源代码:
throw() {
if (!this.isEmpty()) {
throw Object.assign(new Error(), bindAll(this));
}
}
所以它基本上只是一个“正常”的错误类型。
我需要检测这个函数抛出的错误类型:
validationResult(req).throw()
这是抛出函数的定义:
throw() {
if (!this.isEmpty()) {
throw Object.assign(new Error(), utils_1.bindAll(this));
}
}
这是 utils_1.bindAll 函数:
exports.bindAll = (object) => {
const protoKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(object));
protoKeys.forEach(key => {
const maybeFn = object[key];
if (typeof maybeFn === 'function' && key !== 'constructor') {
object[key] = maybeFn.bind(object);
}
});
return object;
};
似乎 throw() 函数不会抛出特定类型的错误,但我需要以某种方式找到它,因为我想以特定方式处理 express-validator 错误。
根据express-validators的源代码:
throw() {
if (!this.isEmpty()) {
throw Object.assign(new Error(), bindAll(this));
}
}
所以它基本上只是一个“正常”的错误类型。