Skip to content

Commit 49fee47

Browse files
Merge branch 'master' into fix/fileupload-auth
2 parents c9a8e0e + 726b913 commit 49fee47

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

src/driver/koa/KoaDriver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ export class KoaDriver extends BaseDriver implements Driver {
9090
};
9191

9292
if (isPromiseLike(checkResult)) {
93-
return checkResult.then(result => handleError(result));
93+
return checkResult
94+
.then(result => handleError(result))
95+
.catch(error => this.handleError(error, actionMetadata, action));
9496
} else {
9597
handleError(checkResult);
9698
}
@@ -290,12 +292,10 @@ export class KoaDriver extends BaseDriver implements Driver {
290292
handleError(error: any, action: ActionMetadata | undefined, options: Action): any {
291293
if (this.isDefaultErrorHandlingEnabled) {
292294
const response: any = options.response;
293-
console.log("ERROR: ", error);
294295

295296
// set http status
296297
// note that we can't use error instanceof HttpError properly anymore because of new typescript emit process
297298
if (error.httpCode) {
298-
console.log("setting status code: ", error.httpCode);
299299
options.context.status = error.httpCode;
300300
response.status = error.httpCode;
301301
} else {

test/functional/action-params.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe("action parameters", () => {
3939
let uploadedFilesFirstName: string;
4040
let uploadedFilesSecondName: string;
4141
let requestReq: any, requestRes: any;
42-
42+
4343
beforeEach(() => {
4444
paramUserId = undefined;
4545
paramFirstId = undefined;
@@ -375,7 +375,6 @@ describe("action parameters", () => {
375375

376376
describe("@Session(param) should allow to inject empty property", () => {
377377
assertRequest([3001, 3002], "get", "session-param-empty", response => {
378-
console.log(response.body);
379378
expect(response).to.be.status(200);
380379
expect(response).to.have.header("content-type", "text/html; charset=utf-8");
381380
expect(response.body).to.be.equal("<html><body>true</body></html>");
@@ -829,7 +828,7 @@ describe("action parameters", () => {
829828
assertRequest([3001, 3002], "post", "photos-with-required", undefined, {}, response => {
830829
expect(response).to.be.status(400);
831830
});
832-
831+
833832
});
834833

835834
});

test/functional/auth-decorator.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,50 @@ describe("Authorized Decorators Http Status Code", function () {
127127
});
128128
});
129129

130+
});
131+
132+
describe("Authorization checker allows to throw", function() {
133+
before(() => {
134+
// reset metadata args storage
135+
getMetadataArgsStorage().reset();
136+
137+
@JsonController()
138+
class AuthController {
139+
@Authorized()
140+
@Get("/auth1")
141+
auth1() {
142+
return { test: "auth1" };
143+
}
144+
145+
}
146+
});
147+
148+
const serverOptions: RoutingControllersOptions = {
149+
authorizationChecker: async (action: Action, roles?: string[]) => {
150+
throw new Error('Custom Error');
151+
}
152+
};
153+
154+
let expressApp: any;
155+
before(done => {
156+
const server = createExpressServer(serverOptions);
157+
expressApp = server.listen(3001, done);
158+
});
159+
after(done => expressApp.close(done));
160+
161+
let koaApp: any;
162+
before(done => {
163+
const server = createKoaServer(serverOptions);
164+
koaApp = server.listen(3002, done);
165+
});
166+
after(done => koaApp.close(done));
167+
168+
describe("custom errors", () => {
169+
assertRequest([3001, 3002], "get", "auth1", response => {
170+
expect(response).to.have.status(500);
171+
expect(response.body).to.have.property("name", "Error");
172+
expect(response.body).to.have.property("message", "Custom Error");
173+
174+
});
175+
});
130176
});

test/functional/express-error-handling.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("express error handling", () => {
1818
errorHandlerCalled = undefined;
1919
errorHandledSpecifically = undefined;
2020
});
21-
21+
2222
before(() => {
2323

2424
// reset metadata args storage
@@ -29,7 +29,7 @@ describe("express error handling", () => {
2929

3030
error(error: any, request: any, response: any, next?: Function): any {
3131
errorHandlerCalled = true;
32-
console.log("ERROR HANDLED GLOBALLY: ", error);
32+
// ERROR HANDLED GLOBALLY
3333
next(error);
3434
}
3535

@@ -39,7 +39,7 @@ describe("express error handling", () => {
3939

4040
error(error: any, request: any, response: any, next?: Function): any {
4141
errorHandledSpecifically = true;
42-
console.log("ERROR HANDLED SPECIFICALLY: ", error);
42+
// ERROR HANDLED SPECIFICALLY
4343
next(error);
4444
}
4545

@@ -48,7 +48,7 @@ describe("express error handling", () => {
4848
class SoftErrorHandler implements ExpressErrorMiddlewareInterface {
4949

5050
error(error: any, request: any, response: any, next?: Function): any {
51-
console.log("ERROR WAS IGNORED: ", error);
51+
// ERROR WAS IGNORED
5252
next();
5353
}
5454

@@ -96,7 +96,7 @@ describe("express error handling", () => {
9696
photos() {
9797
return "1234";
9898
}
99-
99+
100100
}
101101
});
102102

test/functional/express-global-before-error-handling.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ describe("custom express global before middleware error handling", () => {
3131
@Middleware({ type: "before" })
3232
class GlobalBeforeMiddleware implements ExpressMiddlewareInterface {
3333
use(request: any, response: any, next?: Function): any {
34-
console.log("GLOBAL BEFORE MIDDLEWARE CALLED");
3534
throw new CustomError();
3635
}
3736
}

test/functional/redirect-decorator.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,17 @@ describe("dynamic redirect", function () {
3434
@Get("/template")
3535
@Redirect("/users/:owner")
3636
template() {
37-
// console.log("/template");
3837
return {owner: "pleerock", repo: "routing-controllers"};
3938
}
4039

4140
@Get("/original")
4241
@Redirect("/users/pleerock")
4342
original() {
44-
// console.log("/original");
4543
}
4644

4745
@Get("/override")
4846
@Redirect("https://api.github.com")
4947
override() {
50-
// console.log("/override");
5148
return "/users/pleerock";
5249
}
5350

0 commit comments

Comments
 (0)