Skip to content

Commit

Permalink
Fix to allow non-native promises
Browse files Browse the repository at this point in the history
  • Loading branch information
RohaanAdvani68 authored and lholznagel committed Aug 28, 2017
1 parent eebb773 commit 56d5af9
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,14 @@ export class InversifyExpressServer {
let args = this.extractParameters(req, res, next, parameterMetadata);
let result: any = this._container.getNamed(TYPE.Controller, controllerName)[key](...args);
// try to resolve promise
if (result && result instanceof Promise) {

result.then((value: any) => {
Promise.resolve(result)
.then((value: any) => {
if (value && !res.headersSent) {
res.send(value);
}
})
.catch((error: any) => {
next(error);
});

} else if (result && !res.headersSent) {
res.send(result);
}
.catch((err: any) => {
next(err); });
};
}

Expand Down

0 comments on commit 56d5af9

Please sign in to comment.