Skip to content

Commit 03ee080

Browse files
author
Robert Jackson
authored
Handle resilient mode errors before accessing result.headers
1 parent b56547d commit 03ee080

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,20 @@ function fastbootExpressMiddleware(distPath, options) {
3030

3131
try {
3232
let result = await fastboot.visit(path, { request: req, response: res });
33-
let responseBody = opts.chunkedResponse ? result.chunks() : result.html();
33+
let body = opts.chunkedResponse ? await result.chunks() : await result.html();
34+
35+
if (result.error) {
36+
log('RESILIENT MODE CAUGHT:', result.error.stack);
37+
next(result.error);
38+
}
3439

35-
let body = await responseBody;
3640
let headers = result.headers;
3741
let statusMessage = result.error ? 'NOT OK ' : 'OK ';
3842

3943
for (var pair of headers.entries()) {
4044
res.append(pair[0], pair[1]);
4145
}
4246

43-
if (result.error) {
44-
log('RESILIENT MODE CAUGHT:', result.error.stack);
45-
next(result.error);
46-
}
47-
4847
log(result.statusCode, statusMessage + path);
4948
res.status(result.statusCode);
5049

0 commit comments

Comments
 (0)