@@ -47,13 +47,13 @@ For example, this is not a good idea:
47
47
``` js
48
48
// XXX WARNING! BAD IDEA!
49
49
50
- var d = require (' domain' ).create ();
50
+ const d = require (' domain' ).create ();
51
51
d .on (' error' , (er ) => {
52
52
// The error won't crash the process, but what it does is worse!
53
53
// Though we've prevented abrupt process restarting, we are leaking
54
54
// resources like crazy if this ever happens.
55
55
// This is no better than process.on('uncaughtException')!
56
- console .log (' error, but oh well' , er .message );
56
+ console .log (` error, but oh well ${ er .message } ` );
57
57
});
58
58
d .run (() => {
59
59
require (' http' ).createServer ((req , res ) => {
@@ -104,9 +104,9 @@ if (cluster.isMaster) {
104
104
// worker processes to serve requests. How it works, caveats, etc.
105
105
106
106
const server = require (' http' ).createServer ((req , res ) => {
107
- var d = domain .create ();
107
+ const d = domain .create ();
108
108
d .on (' error' , (er ) => {
109
- console .error (' error' , er .stack );
109
+ console .error (` error ${ er .stack } ` );
110
110
111
111
// Note: we're in dangerous territory!
112
112
// By definition, something unexpected occurred,
@@ -115,7 +115,7 @@ if (cluster.isMaster) {
115
115
116
116
try {
117
117
// make sure we close down within 30 seconds
118
- var killtimer = setTimeout (() => {
118
+ const killtimer = setTimeout (() => {
119
119
process .exit (1 );
120
120
}, 30000 );
121
121
// But don't keep the process open just for that!
@@ -135,7 +135,7 @@ if (cluster.isMaster) {
135
135
res .end (' Oops, there was a problem!\n ' );
136
136
} catch (er2) {
137
137
// oh well, not much we can do at this point.
138
- console .error (' Error sending 500!' , er2 .stack );
138
+ console .error (` Error sending 500! ${ er2 .stack } ` );
139
139
}
140
140
});
141
141
@@ -156,7 +156,7 @@ if (cluster.isMaster) {
156
156
// This part is not important. Just an example routing thing.
157
157
// You'd put your fancy application logic here.
158
158
function handleRequest (req , res ) {
159
- switch (req .url ) {
159
+ switch (req .url ) {
160
160
case ' /error' :
161
161
// We do some async stuff, and then...
162
162
setTimeout (() => {
@@ -239,16 +239,16 @@ serverDomain.run(() => {
239
239
// req and res are also created in the scope of serverDomain
240
240
// however, we'd prefer to have a separate domain for each request.
241
241
// create it first thing, and add req and res to it.
242
- var reqd = domain .create ();
242
+ const reqd = domain .create ();
243
243
reqd .add (req);
244
244
reqd .add (res);
245
245
reqd .on (' error' , (er ) => {
246
246
console .error (' Error' , er, req .url );
247
247
try {
248
248
res .writeHead (500 );
249
249
res .end (' Error occurred, sorry.' );
250
- } catch (er ) {
251
- console .error (' Error sending 500' , er , req .url );
250
+ } catch (er2 ) {
251
+ console .error (' Error sending 500' , er2 , req .url );
252
252
}
253
253
});
254
254
}).listen (1337 );
0 commit comments