0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

[ci] format

This commit is contained in:
Fred K. Schott 2024-02-01 21:26:08 +00:00 committed by astrobot-houston
parent 5d08a69f83
commit 055bd27d9d
2 changed files with 25 additions and 27 deletions

View file

@ -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');
}
}
}

View file

@ -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.');
}
});