Skip to content

Commit

Permalink
Merge pull request goldbergyoni#150 from aecorredor/patch-1
Browse files Browse the repository at this point in the history
Update shuttingtheprocess.md
  • Loading branch information
BrunoScheufler authored Mar 9, 2018
2 parents ecf1fe9 + 0d1a4fb commit 7065eb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ This repository is being kept up to date thanks to the help from the community.
🌻 [Allen Fang](https://github.com/AllenFang),
🌻 [Leonardo Villela](https://github.com/leonardovillela),
🌻 [Michal Zalecki](https://github.com/MichalZalecki)
🌻 [Chris Nicola](https://github.com/chrisnicola)

🌻 [Chris Nicola](https://github.com/chrisnicola),
🌻 [Alejandro Corredor](https://github.com/aecorredor)



Expand Down
19 changes: 11 additions & 8 deletions sections/errorhandling/shuttingtheprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ process.on('uncaughtException', function(error) {


// centralized error handler encapsulates error-handling related logic
function errorHandler(){
function errorHandler() {
this.handleError = function (error) {
return logger.logError(err).then(sendMailToAdminIfCritical).then(saveInOpsQueueIfCritical).then(determineIfOperationalError);
return logger.logError(err)
.then(sendMailToAdminIfCritical)
.then(saveInOpsQueueIfCritical)
.then(determineIfOperationalError);
}

this.isTrustedError = function (error) {
return error.isOperational;
}
}

this.isTrustedError = function (error) {
return error.isOperational;
}

```


Expand All @@ -49,4 +52,4 @@ From the blog: JS Recipes
### Blog Quote: "No safe way to leave without creating some undefined brittle state"
From Node.js official documentation

> …By the very nature of how throw works in JavaScript, there is almost never any way to safely “pick up where you left off”, without leaking references, or creating some other sort of undefined brittle state. The safest way to respond to a thrown error is to shut down the process. Of course, in a normal web server, you might have many connections open, and it is not reasonable to abruptly shut those down because an error was triggered by someone else. The better approach is to send an error response to the request that triggered the error, while letting the others finish in their normal time, and stop listening for new requests in that worker.
> …By the very nature of how throw works in JavaScript, there is almost never any way to safely “pick up where you left off”, without leaking references, or creating some other sort of undefined brittle state. The safest way to respond to a thrown error is to shut down the process. Of course, in a normal web server, you might have many connections open, and it is not reasonable to abruptly shut those down because an error was triggered by someone else. The better approach is to send an error response to the request that triggered the error, while letting the others finish in their normal time, and stop listening for new requests in that worker.

0 comments on commit 7065eb2

Please sign in to comment.