-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(templates): fix error middleware handling
- Loading branch information
1 parent
91109ff
commit d4d194a
Showing
7 changed files
with
40 additions
and
52 deletions.
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7
application-templates/javascript/event/src/middleware/error.middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; | ||
|
7 changes: 4 additions & 3 deletions
7
application-templates/javascript/job/src/middleware/error.middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; | ||
|
7 changes: 4 additions & 3 deletions
7
application-templates/javascript/service/src/middleware/error.middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; | ||
|
23 changes: 9 additions & 14 deletions
23
application-templates/typescript/event/src/middleware/error.middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
23 changes: 9 additions & 14 deletions
23
application-templates/typescript/job/src/middleware/error.middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
23 changes: 9 additions & 14 deletions
23
application-templates/typescript/service/src/middleware/error.middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.