Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit a02e721

Browse files
committed
Fix bug where syntax errors would result in no response.
We had a test for this, but it didn't account for the case where the downstream body was a stream, in which case we were consuming it and never setting a new body.
1 parent 28b79fc commit a02e721

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
Unreleased section, uncommenting the header as necessary.
1111
-->
1212

13-
<!-- ## Unreleased -->
13+
## Unreleased
14+
- Fixed issue where syntax errors encountered in files would result in an empty response.
1415
<!-- Add new unreleased items here -->
1516

1617
## [1.0.0-pre.5] - 2019-06-25

src/koa-module-specifier-transform.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ export const moduleSpecifierTransform =
167167
logger.error(
168168
`Unable to transform module specifiers in "${url}" due to`,
169169
error);
170+
// We want errors to result in serving the unchanged original file. If
171+
// body was a stream then we've already consumed it, so we need to
172+
// assign the string copy here.
173+
ctx.body = body;
170174
}
171175
};
172176
};

src/test/test-utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import {Server} from 'http';
1515
import Koa from 'koa';
1616
import route from 'koa-route';
17+
import {Readable} from 'stream';
18+
1719
import {Logger} from '../support/logger';
1820

1921
export type AppOptions = {
@@ -39,7 +41,12 @@ export const createApp = (options: AppOptions): Koa => {
3941
if (key.endsWith('.html')) {
4042
ctx.type = 'html';
4143
}
42-
ctx.body = value;
44+
// Make our body a stream, like koa static would do, to make sure we
45+
// aren't, for example, consuming the body streams.
46+
const stream = new Readable();
47+
stream.push(value);
48+
stream.push(null);
49+
ctx.body = stream;
4350
}));
4451
}
4552
}

0 commit comments

Comments
 (0)