Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f358d8e

Browse filesBrowse files
In HttpNodeInstance, correctly report response serialisation errors back to .NET (previously, it just timed out)
1 parent 465d0c8 commit f358d8e
Copy full SHA for f358d8e

File tree

Expand file treeCollapse file tree

2 files changed

+30
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+30
-16
lines changed
Open diff view settings
Collapse file

‎src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-http.js‎

Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-http.js
+15-8Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,21 @@
6969
if (!hasSentResult) {
7070
hasSentResult = true;
7171
if (errorValue) {
72-
res.statusCode = 500;
73-
if (errorValue.stack) {
74-
res.end(errorValue.stack);
75-
}
76-
else {
77-
res.end(errorValue.toString());
78-
}
72+
respondWithError(res, errorValue);
7973
}
8074
else if (typeof successValue !== 'string') {
8175
// Arbitrary object/number/etc - JSON-serialize it
76+
var successValueJson = void 0;
77+
try {
78+
successValueJson = JSON.stringify(successValue);
79+
}
80+
catch (ex) {
81+
// JSON serialization error - pass it back to .NET
82+
respondWithError(res, ex);
83+
return;
84+
}
8285
res.setHeader('Content-Type', 'application/json');
83-
res.end(JSON.stringify(successValue));
86+
res.end(JSON.stringify(successValueJson));
8487
}
8588
else {
8689
// String - can bypass JSON-serialization altogether
@@ -129,6 +132,10 @@
129132
.on('data', function (chunk) { requestBodyAsString += chunk; })
130133
.on('end', function () { callback(JSON.parse(requestBodyAsString)); });
131134
}
135+
function respondWithError(res, errorValue) {
136+
res.statusCode = 500;
137+
res.end(errorValue.stack || errorValue.toString());
138+
}
132139

133140

134141
/***/ },
Collapse file

‎src/Microsoft.AspNetCore.NodeServices/TypeScript/HttpNodeInstanceEntryPoint.ts‎

Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.NodeServices/TypeScript/HttpNodeInstanceEntryPoint.ts
+15-8Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ const server = http.createServer((req, res) => {
1717
if (!hasSentResult) {
1818
hasSentResult = true;
1919
if (errorValue) {
20-
res.statusCode = 500;
21-
22-
if (errorValue.stack) {
23-
res.end(errorValue.stack);
24-
} else {
25-
res.end(errorValue.toString());
26-
}
20+
respondWithError(res, errorValue);
2721
} else if (typeof successValue !== 'string') {
2822
// Arbitrary object/number/etc - JSON-serialize it
23+
let successValueJson: string;
24+
try {
25+
successValueJson = JSON.stringify(successValue);
26+
} catch (ex) {
27+
// JSON serialization error - pass it back to .NET
28+
respondWithError(res, ex);
29+
return;
30+
}
2931
res.setHeader('Content-Type', 'application/json');
30-
res.end(JSON.stringify(successValue));
32+
res.end(JSON.stringify(successValueJson));
3133
} else {
3234
// String - can bypass JSON-serialization altogether
3335
res.setHeader('Content-Type', 'text/plain');
@@ -82,3 +84,8 @@ function readRequestBodyAsJson(request, callback) {
8284
.on('data', chunk => { requestBodyAsString += chunk; })
8385
.on('end', () => { callback(JSON.parse(requestBodyAsString)); });
8486
}
87+
88+
function respondWithError(res: http.ServerResponse, errorValue: any) {
89+
res.statusCode = 500;
90+
res.end(errorValue.stack || errorValue.toString());
91+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.