Typescript question: What is the specific error type associated with the 'throw' function in express-validator?

I am trying to identify the type of error thrown by this function:

validationResult(req).throw()

This is how the throw function is defined:

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

Here is the utils_1.bindAll function for reference:

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 appears that the throw() function does not specify a particular error type, but I need to figure it out in order to handle express-validator errors in a specific manner.

Answer №1

As outlined in the express-validators source code:

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

Hence, it essentially functions as a standard Error Type.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshoot: Issue with injecting external component into another component using directive in Angular 2

I need the child component template to be loaded into the parent component template. (calling them child and parent for simplicity) Here is the child component: import {Component,Directive, ElementRef, Input} from '@angular/core'; import {IONIC ...

Unable to locate 'http' in error handling service for Angular 6

My current project involves creating an Error Handling Service for an Angular 6 Application using the HTTP Interceptor. The main goal of this service is to capture any HTTP errors and provide corresponding error codes. However, my lack of familiarity with ...

AngularJS ui-router behaving erratically when manually refreshing the page

While working on an application with my team, we've noticed some inconsistent behavior. When a user refreshes the browser, the page UI state is fully refreshed, but only up to a certain route. Our application starts on the /Home route, establishing t ...

The Vue API client fetches necessary information from the server and generates a .csv file with accurate headers and IDs. However, the data retrieved is incomplete

Check out my code repository here: https://github.com/d0uble-happiness/discogsCSV App.vue <template> <div> <button @click="downloadSampleInputFile">Download basic sample file</button> </div> < ...

How does putting a '$' symbol before an event impact functionality in Angular?

How does prefacing an event with a '$' dollar sign impact Angular? onModelUpdated($event: any) { console.log($event); } vs onModelUpdated(event: any) { console.log(event); } ...

Handling Errors in Angular 4

If a client sends a POST request with a LicenseNumber that already exists in the database (and must be unique), the server will respond as follows: {"errorCode":"Validation Error", "errorMessage":"Invalid inputs.", ...

Incorporating FormControl Validators within a Child Component in Angular

Having two Angular Components, one is called parent.ts and the other is named child.ts. Parent.ts contains a Form group, while child.ts passes the Form data via CVA to the parent. Now, I am looking to create a reusable child component that can generate c ...

Function with a TypeScript Union Type

I'm attempting to define a property that can be either a lambda function or a string in TypeScript. class TestClass { name: string | () => string; } You can find a sample of non-working code on the TS playground here. However, when compiling ...

Strict mode error occurs when attempting to assign a value to ngComponentOutlet that is incompatible with the type of the lazy-loaded component

I am attempting to implement lazy loading for a component in Angular 11 (strict mode) using guidance from this tutorial. Dealing with strict mode has been challenging as there are very few resources available that cater to it. The goal is to have a compon ...

Revamping Angular Material Table - A guide to refreshing column headers in a pre-existing table

I am currently working on an Angular 7 project where I have implemented a basic component that utilizes an Angular Material Table. I want to be able to update both the data and the header of the table when a certain event occurs, such as a mouse click. Be ...

Styling of Bootstrap HTML element not appearing as expected

Recently, I've been trying out a new approach by embedding Bootstrap components in an iframe. However, despite loading the necessary stylesheet and scripts, the elements seem to be missing their styles. Can anyone shed some light on why this might be ...

Exploring the mechanics behind optional chaining, known as the Elvis operator, in TypeScript. How does this feature operate within the

Can someone explain the concept of optional chaining (Elvis operator) in TypeScript and how it can be used effectively? public static getName(user: IUser){ if(user.firstName != null && user.firstName != ""){ return user.firstName; } ...

Facing an issue with the TypeScript error in the Tailwind-Styled-Component Npm package. Any suggestions on how to troub

module.styles.ts File import tw from "tailwind-styled-components"; export const Wrapper = tw.div` bg-green-500 `; export const Link = tw.a` text-blue-500 `; home.jsx File import React from "react"; import { Wrapper, Link } from &qu ...

How can you verify the anticipated log output in the midst of a function execution with Jest unit testing?

Below is a demonstration function I have: export async function myHandler( param1: string, param2: string, req: Request, next: NextFunction, ) { const log = req.log.prefix(`[my=prefix]`); let res; If (param1 === 'param1&a ...

What is the best way to assign the value of "this" to a variable within a component using Angular 2 and TypeScript?

In my component, I have the following setup: constructor() { this.something = "Hello"; } document.addEventListener('click', doSomething()); function doSomething(e) { console.log(this.something) // this is undefined } I am struggling to a ...

How to retrieve the parent activated route in Angular 2

My route structure includes parent and child routes as shown below: { path: 'dashboard', children: [{ path: '', canActivate: [CanActivateAuthGuard], component: DashboardComponent }, { path: & ...

Using @ViewChild and AfterViewInit to access the nativeElement of a component

Note: While my question may seem similar to others, the specifics are different. I am attempting to execute a function on an element that is contained within a <ng-template>. Due to the fact that it is not rendered in the DOM, I am encountering diff ...

Storing my token in the cookie using setCookie is proving to be difficult for me

While trying to authenticate my site with nextAuth and nookies, I am facing an issue where the token is not getting stored in the cookie. The API sends back a token and a refresh, and even though storing the refresh works fine, the token just doesn't ...

Error: Unable to attach the "identity" property as the object does not support extension

I encountered a simple TypeError while attempting to format my POST body. Below is the function I am using for handleSubmit : const handleSubmit = (values: any, formikHelpers: FormikHelpers<any>) => { const prepareBody = { ...values.customerC ...

Creating a unique user interface for VSCode extension

Recently, I've delved into the world of developing extensions for Visual Studio. Unfortunately, my expertise in TypeScript and Visual Studio Code is quite limited. My goal is to create an extension that mirrors the functionality of activate-power-mod ...