Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

381
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda