Skip to content

Commit

Permalink
Merge pull request #5 from otbe/rejected-promises
Browse files Browse the repository at this point in the history
Added support for rejected promises
  • Loading branch information
remojansen authored Jul 4, 2016
2 parents 596a872 + db7dd1f commit dd97da3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export class InversifyExpressServer {
if (value && !res.headersSent) {
res.send(value);
}
});
})
.catch((error: any) => {
next(error);
});

} else if (result && !res.headersSent) {
res.send(result);
Expand Down
18 changes: 18 additions & 0 deletions test/framework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ describe("Integration Tests:", () => {
.expect(200, "GET", done);
});

it("should work for async controller methods that fails", (done) => {
@injectable()
@Controller("/")
class TestController {
@Get("/") public getTest(req: express.Request, res: express.Response) {
return new Promise(((resolve, reject) => {
setTimeout(reject, 100, "GET");
}));
}
}
kernel.bind<interfaces.Controller>("Controller").to(TestController).whenTargetNamed("TestController");

server = new InversifyExpressServer(kernel);
request(server.build())
.get("/")
.expect(500, done);
});


it ("should work for methods which call next()", (done) => {
@injectable()
Expand Down

0 comments on commit dd97da3

Please sign in to comment.