mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-10-30 00:57:04 +08:00
[Chinese-translation]shuttingtheprocess.chinese.md - finished.
This commit is contained in:
@ -10,8 +10,8 @@
|
||||
### 代码实例: 决定是否退出
|
||||
|
||||
```javascript
|
||||
//deciding whether to crash when an uncaught exception arrives
|
||||
//Assuming developers mark known operational errors with error.isOperational=true, read best practice #3
|
||||
//收到未捕获的异常时,决定是否要崩溃
|
||||
//如果开发人员标记已知的操作型错误使用:error.isOperational=true, 查看最佳实践 #3
|
||||
process.on('uncaughtException', function(error) {
|
||||
errorManagement.handler.handleError(error);
|
||||
if(!errorManagement.handler.isTrustedError(error))
|
||||
@ -19,7 +19,7 @@ process.on('uncaughtException', function(error) {
|
||||
});
|
||||
|
||||
|
||||
//centralized error handler encapsulates error-handling related logic
|
||||
//封装错误处理相关逻辑在集中的错误处理中
|
||||
function errorHandler(){
|
||||
this.handleError = function (error) {
|
||||
return logger.logError(err).then(sendMailToAdminIfCritical).then(saveInOpsQueueIfCritical).then(determineIfOperationalError);
|
||||
@ -33,14 +33,14 @@ function errorHandler(){
|
||||
```
|
||||
|
||||
|
||||
### Blog Quote: "The best way is to crash"
|
||||
From the blog Joyent
|
||||
### 博客引用: "最好的方式是立即崩溃"
|
||||
摘自 博客:Joyent
|
||||
|
||||
> …从程序型错误中恢复过来的最好方法是立即崩溃。你应该使用一个重启助手来运行您的程序,它会在崩溃的情况下自动启动程序。当使用重启助手,崩溃是面对临时性的程序型错误时,恢复可靠的服务的最快的方法…
|
||||
|
||||
|
||||
### Blog Quote: "错误处理有三种流派"
|
||||
From the blog: JS Recipes
|
||||
### 博客引用: "错误处理有三种流派"
|
||||
摘自 博客:JS Recipes
|
||||
|
||||
> …错误处理主要有三种流派:
|
||||
1. 让应用崩溃,并重启。
|
||||
@ -48,7 +48,7 @@ function errorHandler(){
|
||||
3. 介于两者之间。
|
||||
|
||||
|
||||
### Blog Quote: "No safe way to leave without creating some undefined brittle state"
|
||||
From Node.JS official documentation
|
||||
### 博客引用: "不伴随着创建一些易碎的状态,是没有保险的方式退出"
|
||||
摘自 Node.JS 官方文档
|
||||
|
||||
> …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.
|
||||
> …就throw工作在JavaScript的本质而言,几乎没有任何方法可以安全地“在您丢下的地方捡起”,而不会泄漏引用,或者创建其他类型的未定义的易碎性状态。对抛出的错误作出响应的最安全的方法是关闭进程。当然,在一个普通的Web服务器中,可能有很多连接打开了,因为其他人触发了一个错误,所以突然关闭这些连接是不合理的。更好的方法是将错误响应发送给触发错误的请求,同时让其他人在正常时间内完成,并停止侦听该工作者的新请求。
|
||||
Reference in New Issue
Block a user