Skip to content

Commit

Permalink
[patch] provide original error for debug purposes (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeoB authored Apr 15, 2020
1 parent c66df9c commit 3a11388
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/subapp-server/lib/setup-hapi-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ async function setupRoutesFromFile(srcDir, server, pluginOpts) {

const data = context.result;
const status = data.status;

if (status === undefined) {
if (data instanceof Error) {
// rethrow to get default error behavior below with helpful errors in dev mode
throw data;
} else if (status === undefined) {
return h.response(data).type("text/html; charset=UTF-8").code(200);
} else if (HttpStatus.redirect[status]) {
return h.redirect(data.path).code(status);
Expand Down
18 changes: 18 additions & 0 deletions packages/subapp-server/test/spec/setup-hapi-routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ describe("setupSubAppHapiRoutes", () => {
delete process.env.NODE_ENV;
});

it("should let the server reply error stack if routeHandler returns an error as a result", async () => {
stubPathResolve = getStubResolve1();
stubRouteHandler = sinon.stub(ReactWebapp, "makeRouteHandler").callsFake(() => async () => ({
result: new Error("Dev error here")
}));
const logs = [];
const stubConsoleError = sinon.stub(console, "error").callsFake(c => logs.push(c));
await setupSubAppHapiRoutes(server, {});
await server.start();
const { result: devResult } = await server.inject({
method: "GET",
url: "/file2"
});
expect(devResult).to.include("Dev error here");
expect(logs[0]).to.equal("Route file2 failed:");
stubConsoleError.restore();
});

it("should throw error if route.htmlFile not defined", async () => {
stubPathResolve = getStubResolve3();
try {
Expand Down

0 comments on commit 3a11388

Please sign in to comment.