Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

383
Vistas
TypeError: _middleware_error__WEBPACK_IMPORTED_MODULE_2__.default is not a constructor

I am making a Login API in NEXT JS, I have made an error handler, but when I call login API it gives me the following error :

TypeError: _middleware_error__WEBPACK_IMPORTED_MODULE_2__.default is not a constructor
} catch (error) {
  return next(
  new ErrorHandler({ "Internal Server Error : ": error.message }, 500)
     ^  
);
}});

Here is my ErrorHandler File :

const ErrorHandler = require("../utils/errorhandler");

module.exports = (err, req, res, next) => {
  err.statusCode = err.statusCode || 500;
  err.message = err.message || "Internal Server Error";

  //Mongo DB Error
  if (err.name === "CastError") {
    const message = `Resource Not Found. Invalid: ${err.path}`;
    err = new ErrorHandler(message, 400);
  }

  res.status(err.statusCode).json({
    success: false,
    message: err.message,
    statusCode: err.statusCode,
  });
};

I am importing a class constructor from my utils/errorhandler here is the code:

class ErrorHander extends Error {
  constructor(message, statusCode) {
    super(message);
    this.statusCode = statusCode;

    Error.captureStackTrace(this, this.constructor);
  }
}

module.exports = ErrorHander;

So basically I am creating a class known as ErrorHandler and then using it to make a error handling function which returns me the error message and the status code. The error says I have some issue with the function, I tried changing it to ES6 but it didn't worked.

I am using NEXT JS API with custom Express Server for backend.

I appreciate your efforts for helping me with this Thank You.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda