diff --git a/application-templates/javascript/event/src/middleware/error.middleware.js b/application-templates/javascript/event/src/middleware/error.middleware.js index 76149dc..ce83655 100644 --- a/application-templates/javascript/event/src/middleware/error.middleware.js +++ b/application-templates/javascript/event/src/middleware/error.middleware.js @@ -1,17 +1,18 @@ import CustomError from '../errors/custom.error.js'; -export const errorMiddleware = (error, _req, res, _next) => { +export const errorMiddleware = (error, _req, res) => { if (error instanceof CustomError) { if (typeof error.statusCode === 'number') { res.status(error.statusCode).json({ message: error.message, errors: error.errors, - stack: error.stack + stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, }); return; } } - res.status(500).send('Internal server error: ' + error.stack); + res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); }; + diff --git a/application-templates/javascript/job/src/middleware/error.middleware.js b/application-templates/javascript/job/src/middleware/error.middleware.js index 76149dc..ce83655 100644 --- a/application-templates/javascript/job/src/middleware/error.middleware.js +++ b/application-templates/javascript/job/src/middleware/error.middleware.js @@ -1,17 +1,18 @@ import CustomError from '../errors/custom.error.js'; -export const errorMiddleware = (error, _req, res, _next) => { +export const errorMiddleware = (error, _req, res) => { if (error instanceof CustomError) { if (typeof error.statusCode === 'number') { res.status(error.statusCode).json({ message: error.message, errors: error.errors, - stack: error.stack + stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, }); return; } } - res.status(500).send('Internal server error: ' + error.stack); + res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); }; + diff --git a/application-templates/javascript/service/src/middleware/error.middleware.js b/application-templates/javascript/service/src/middleware/error.middleware.js index 76149dc..ce83655 100644 --- a/application-templates/javascript/service/src/middleware/error.middleware.js +++ b/application-templates/javascript/service/src/middleware/error.middleware.js @@ -1,17 +1,18 @@ import CustomError from '../errors/custom.error.js'; -export const errorMiddleware = (error, _req, res, _next) => { +export const errorMiddleware = (error, _req, res) => { if (error instanceof CustomError) { if (typeof error.statusCode === 'number') { res.status(error.statusCode).json({ message: error.message, errors: error.errors, - stack: error.stack + stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, }); return; } } - res.status(500).send('Internal server error: ' + error.stack); + res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); }; + diff --git a/application-templates/typescript/event/src/middleware/error.middleware.ts b/application-templates/typescript/event/src/middleware/error.middleware.ts index 14ea798..75cda75 100644 --- a/application-templates/typescript/event/src/middleware/error.middleware.ts +++ b/application-templates/typescript/event/src/middleware/error.middleware.ts @@ -1,25 +1,20 @@ -import { ErrorRequestHandler, NextFunction, Request, Response } from 'express'; +import { ErrorRequestHandler, Request, Response } from 'express'; import CustomError from '../errors/custom.error'; - export const errorMiddleware: ErrorRequestHandler = ( error: Error, - req: Request, + _: Request, res: Response, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - next: NextFunction ) => { if (error instanceof CustomError) { - - res.status(error.statusCode as number).json({ - message: error.message, - errors: error.errors, - stack: error.stack, - }); + res.status(error.statusCode as number).json({ + message: error.message, + errors: error.errors, + stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, + }); - return; - + return; } - res.status(500).send('Internal server error: ' + error.stack); + res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); }; diff --git a/application-templates/typescript/job/src/middleware/error.middleware.ts b/application-templates/typescript/job/src/middleware/error.middleware.ts index 14ea798..75cda75 100644 --- a/application-templates/typescript/job/src/middleware/error.middleware.ts +++ b/application-templates/typescript/job/src/middleware/error.middleware.ts @@ -1,25 +1,20 @@ -import { ErrorRequestHandler, NextFunction, Request, Response } from 'express'; +import { ErrorRequestHandler, Request, Response } from 'express'; import CustomError from '../errors/custom.error'; - export const errorMiddleware: ErrorRequestHandler = ( error: Error, - req: Request, + _: Request, res: Response, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - next: NextFunction ) => { if (error instanceof CustomError) { - - res.status(error.statusCode as number).json({ - message: error.message, - errors: error.errors, - stack: error.stack, - }); + res.status(error.statusCode as number).json({ + message: error.message, + errors: error.errors, + stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, + }); - return; - + return; } - res.status(500).send('Internal server error: ' + error.stack); + res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); }; diff --git a/application-templates/typescript/service/src/middleware/error.middleware.ts b/application-templates/typescript/service/src/middleware/error.middleware.ts index 14ea798..75cda75 100644 --- a/application-templates/typescript/service/src/middleware/error.middleware.ts +++ b/application-templates/typescript/service/src/middleware/error.middleware.ts @@ -1,25 +1,20 @@ -import { ErrorRequestHandler, NextFunction, Request, Response } from 'express'; +import { ErrorRequestHandler, Request, Response } from 'express'; import CustomError from '../errors/custom.error'; - export const errorMiddleware: ErrorRequestHandler = ( error: Error, - req: Request, + _: Request, res: Response, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - next: NextFunction ) => { if (error instanceof CustomError) { - - res.status(error.statusCode as number).json({ - message: error.message, - errors: error.errors, - stack: error.stack, - }); + res.status(error.statusCode as number).json({ + message: error.message, + errors: error.errors, + stack: process.env.NODE_ENV === 'development' ? error.stack : undefined, + }); - return; - + return; } - res.status(500).send('Internal server error: ' + error.stack); + res.status(500).send('Internal server error: ' + process.env.NODE_ENV === 'development' ? error.stack : undefined); }; diff --git a/package-lock.json b/package-lock.json index 951fe00..7cb038f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13664,7 +13664,7 @@ }, "packages/create-connect-app": { "name": "@commercetools-connect/create-connect-app", - "version": "0.3.0", + "version": "0.4.0", "license": "MIT", "dependencies": { "cac": "^6.7.14",