Arman
Arman

Reputation: 960

Typescript: What is the error type of 'throw' function in express-validator?

I need to detect the error type that this function throws:

validationResult(req).throw()

This is the defenition of throw function:

throw() {
    if (!this.isEmpty()) {
        throw Object.assign(new Error(), utils_1.bindAll(this));
    }
}

And this is the utils_1.bindAll function:

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;
};

It seems that throw() function doesn't throw an error with a specific type but I need to somehow find it because I want to handle express-validator errors in a particular way.

Upvotes: 0

Views: 238

Answers (1)

Braks
Braks

Reputation: 639

According to the source code of express-validators:

throw() {
    if (!this.isEmpty()) {
      throw Object.assign(new Error(), bindAll(this));
    }
  }

So it's basically just a "normal" Error Type.

Upvotes: 1

Related Questions