Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Feb 1, 2024
1 parent 5d08a69 commit 055bd27
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
44 changes: 22 additions & 22 deletions packages/astro/src/core/app/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

Expand Down
8 changes: 3 additions & 5 deletions packages/integrations/node/test/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
});
Expand Down

0 comments on commit 055bd27

Please sign in to comment.