Skip to content

Commit

Permalink
Merge pull request #10 from ostrojs/develop
Browse files Browse the repository at this point in the history
terminate middleware and report exception bug fix (#9)
  • Loading branch information
amarksingh authored Dec 4, 2023
2 parents 316fc5d + a366013 commit 13c7c68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 7 additions & 5 deletions exception/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ class Handler {
constructor(handler) {
this[kHandle] = handler
this[kLogger] = app('logger')

}

handle(request, response, $e = {}) {
this.render(request, response, $e)
}

terminate(request, response, $e = {}) {
this.report($e)
}

render(request, response, $e = {}) {
Expand Down Expand Up @@ -133,22 +135,22 @@ class Handler {
} else {
return fs.readFile(path.join(__dirname, 'template/errors/403'), {
encoding: 'utf8'
}, function(error, data) {
}, function (error, data) {
response.send(data, $e.statusCode)
})
}
}
pageNotFoundException(request, response, $e) {
return fs.readFile(path.join(__dirname, 'template/errors/404'), {
encoding: 'utf8'
}, function(error, data) {
}, function (error, data) {
response.send(data, $e.statusCode)
})
}
report($e) {
if (!this.$dontReport.find((clazz) => $e instanceof clazz)) {
if (typeof this[kLogger].getConfig == 'function' && !this[kLogger].getConfig('ignore_exceptions')) {
if (typeof $e == 'object') {
if ($e && typeof $e == 'object') {
if (typeof $e.stack == 'string') {
$e.capture = $e.stack.split('\n at ')
}
Expand All @@ -161,4 +163,4 @@ class Handler {
this[kLogger].channel('console').error($e)
}
}
module.exports = Handler
module.exports = Handler
9 changes: 8 additions & 1 deletion exception/middleware/exceptionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class ExceptionHandler {
error
)
}
terminate(error, {request,response} ,next){
this.$exceptionHandler.handler('json').terminate(
request,
response,
error
)
}
}

module.exports = ExceptionHandler
module.exports = ExceptionHandler

0 comments on commit 13c7c68

Please sign in to comment.