diff --git a/application-templates/javascript/event/src/middleware/error.middleware.js b/application-templates/javascript/event/src/middleware/error.middleware.js index ce83655..722bb95 100644 --- a/application-templates/javascript/event/src/middleware/error.middleware.js +++ b/application-templates/javascript/event/src/middleware/error.middleware.js @@ -1,18 +1,17 @@ import CustomError from '../errors/custom.error.js'; export const errorMiddleware = (error, _req, res) => { + const isDevelopment = process.env.NODE_ENV === 'development'; + if (error instanceof CustomError) { - if (typeof error.statusCode === 'number') { - res.status(error.statusCode).json({ - message: error.message, - errors: error.errors, - stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, - }); + res.status(error.statusCode).json({ + message: error.message, + errors: error.errors, + stack: isDevelopment ? error.stack : undefined, + }); - return; - } + return; } - res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); -}; - + res.status(500).send(isDevelopment ? error : 'Internal server error'); +}; \ No newline at end of file diff --git a/application-templates/javascript/job/src/middleware/error.middleware.js b/application-templates/javascript/job/src/middleware/error.middleware.js index ce83655..722bb95 100644 --- a/application-templates/javascript/job/src/middleware/error.middleware.js +++ b/application-templates/javascript/job/src/middleware/error.middleware.js @@ -1,18 +1,17 @@ import CustomError from '../errors/custom.error.js'; export const errorMiddleware = (error, _req, res) => { + const isDevelopment = process.env.NODE_ENV === 'development'; + if (error instanceof CustomError) { - if (typeof error.statusCode === 'number') { - res.status(error.statusCode).json({ - message: error.message, - errors: error.errors, - stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, - }); + res.status(error.statusCode).json({ + message: error.message, + errors: error.errors, + stack: isDevelopment ? error.stack : undefined, + }); - return; - } + return; } - res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); -}; - + res.status(500).send(isDevelopment ? error : 'Internal server error'); +}; \ No newline at end of file diff --git a/application-templates/javascript/service/src/middleware/error.middleware.js b/application-templates/javascript/service/src/middleware/error.middleware.js index ce83655..722bb95 100644 --- a/application-templates/javascript/service/src/middleware/error.middleware.js +++ b/application-templates/javascript/service/src/middleware/error.middleware.js @@ -1,18 +1,17 @@ import CustomError from '../errors/custom.error.js'; export const errorMiddleware = (error, _req, res) => { + const isDevelopment = process.env.NODE_ENV === 'development'; + if (error instanceof CustomError) { - if (typeof error.statusCode === 'number') { - res.status(error.statusCode).json({ - message: error.message, - errors: error.errors, - stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, - }); + res.status(error.statusCode).json({ + message: error.message, + errors: error.errors, + stack: isDevelopment ? error.stack : undefined, + }); - return; - } + return; } - res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); -}; - + res.status(500).send(isDevelopment ? error : 'Internal server error'); +}; \ No newline at end of file diff --git a/application-templates/typescript/event/src/middleware/error.middleware.ts b/application-templates/typescript/event/src/middleware/error.middleware.ts index 75cda75..1315d55 100644 --- a/application-templates/typescript/event/src/middleware/error.middleware.ts +++ b/application-templates/typescript/event/src/middleware/error.middleware.ts @@ -4,17 +4,19 @@ import CustomError from '../errors/custom.error'; export const errorMiddleware: ErrorRequestHandler = ( error: Error, _: Request, - res: Response, + res: Response ) => { +const isDevelopment = process.env.NODE_ENV === 'development'; + if (error instanceof CustomError) { res.status(error.statusCode as number).json({ message: error.message, errors: error.errors, - stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, + stack: isDevelopment ? error.stack : undefined, }); return; } - res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); -}; + res.status(500).send(isDevelopment ? error : 'Internal server error'); +}; \ No newline at end of file diff --git a/application-templates/typescript/job/src/middleware/error.middleware.ts b/application-templates/typescript/job/src/middleware/error.middleware.ts index 75cda75..1315d55 100644 --- a/application-templates/typescript/job/src/middleware/error.middleware.ts +++ b/application-templates/typescript/job/src/middleware/error.middleware.ts @@ -4,17 +4,19 @@ import CustomError from '../errors/custom.error'; export const errorMiddleware: ErrorRequestHandler = ( error: Error, _: Request, - res: Response, + res: Response ) => { +const isDevelopment = process.env.NODE_ENV === 'development'; + if (error instanceof CustomError) { res.status(error.statusCode as number).json({ message: error.message, errors: error.errors, - stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, + stack: isDevelopment ? error.stack : undefined, }); return; } - res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); -}; + res.status(500).send(isDevelopment ? error : 'Internal server error'); +}; \ No newline at end of file diff --git a/application-templates/typescript/service/src/middleware/error.middleware.ts b/application-templates/typescript/service/src/middleware/error.middleware.ts index 75cda75..1315d55 100644 --- a/application-templates/typescript/service/src/middleware/error.middleware.ts +++ b/application-templates/typescript/service/src/middleware/error.middleware.ts @@ -4,17 +4,19 @@ import CustomError from '../errors/custom.error'; export const errorMiddleware: ErrorRequestHandler = ( error: Error, _: Request, - res: Response, + res: Response ) => { +const isDevelopment = process.env.NODE_ENV === 'development'; + if (error instanceof CustomError) { res.status(error.statusCode as number).json({ message: error.message, errors: error.errors, - stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, + stack: isDevelopment ? error.stack : undefined, }); return; } - res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); -}; + res.status(500).send(isDevelopment ? error : 'Internal server error'); +}; \ No newline at end of file