summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/src/core/app/node.ts44
-rw-r--r--packages/integrations/node/test/errors.test.js8
2 files changed, 25 insertions, 27 deletions
diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts
index ccb206830..439d056da 100644
--- a/packages/astro/src/core/app/node.ts
+++ b/packages/astro/src/core/app/node.ts
@@ -99,30 +99,30 @@ export class NodeApp extends App {
const { status, headers, body } = source;
destination.writeHead(status, createOutgoingHttpHeaders(headers));
if (!body) return destination.end();
- try {
- const reader = body.getReader();
- destination.on('close', () => {
- // Cancelling the reader may reject not just because of
- // an error in the ReadableStream's cancel callback, but
- // also because of an error anywhere in the stream.
- reader.cancel().catch((err) => {
- // eslint-disable-next-line no-console
- console.error(
- `There was an uncaught error in the middle of the stream while rendering ${destination.req.url}.`,
- err
- );
- });
+ try {
+ const reader = body.getReader();
+ destination.on('close', () => {
+ // Cancelling the reader may reject not just because of
+ // an error in the ReadableStream's cancel callback, but
+ // also because of an error anywhere in the stream.
+ reader.cancel().catch((err) => {
+ // eslint-disable-next-line no-console
+ console.error(
+ `There was an uncaught error in the middle of the stream while rendering ${destination.req.url}.`,
+ err
+ );
});
- let result = await reader.read();
- while (!result.done) {
- destination.write(result.value);
- result = await reader.read();
- }
- destination.end();
- // the error will be logged by the "on end" callback above
- } catch {
- destination.end('Internal server error');
+ });
+ let result = await reader.read();
+ while (!result.done) {
+ destination.write(result.value);
+ result = await reader.read();
}
+ destination.end();
+ // the error will be logged by the "on end" callback above
+ } catch {
+ destination.end('Internal server error');
+ }
}
}
diff --git a/packages/integrations/node/test/errors.test.js b/packages/integrations/node/test/errors.test.js
index 8d54bcd4e..09fc9e734 100644
--- a/packages/integrations/node/test/errors.test.js
+++ b/packages/integrations/node/test/errors.test.js
@@ -43,13 +43,11 @@ describe('Errors', () => {
const chunk3 = await reader.read();
assert.equal(chunk1.done, false);
if (chunk2.done) {
- assert.equal(decoder.decode(chunk1.value), result.join(""));
- }
- else if (chunk3.done) {
+ assert.equal(decoder.decode(chunk1.value), result.join(''));
+ } else if (chunk3.done) {
assert.equal(decoder.decode(chunk1.value), result[0]);
assert.equal(decoder.decode(chunk2.value), result[1]);
- }
- else {
+ } else {
throw new Error('The response should take at most 2 chunks.');
}
});