koa server always responds 404
In koa async controller function, if I set @Authroized() , server always responds "404 Not Found"
I think this code Incorrect
const handleError = (result: any) => {
if (!result) {
let error = actionMetadata.authorizedRoles.length === 0 ? new AuthorizationRequiredError(action) : new AccessDeniedError(action);
return this.handleError(error, actionMetadata, action);
} else {
next();
}
};
if (isPromiseLike(checkResult)) {
checkResult.then(result => handleError(result));
} else {
handleError(checkResult);
}
https://github.com/pleerock/routing-controllers/blob/master/src/driver/koa/KoaDriver.ts#L101-L108
it should be modified as follows.
const handleError = (result: any) => {
if (!result) {
let error = actionMetadata.authorizedRoles.length === 0 ? new AuthorizationRequiredError(action) : new AccessDeniedError(action);
return this.handleError(error, actionMetadata, action);
} else {
return next();
}
};
if (isPromiseLike(checkResult)) {
return checkResult.then(result => handleError(result));
} else {
return Promise.resolve(handleError(checkResult));
}
https://github.com/mingyang91/routing-controllers/blob/master/src/driver/koa/KoaDriver.ts#L107-L114
Could you make a PR and test the changes? 😉
Same is happening for me using koa@2 with a non-async controller action decorated with @Authorized(). The response gets sent back with a 404 status before the controller action even runs.
@mingyang91 Will you find some time to make a PR as you described the problem and found the fix? https://github.com/mingyang91/routing-controllers/commit/38a68e6fa1ef73439c8ca7c40225608a9be62aa3#diff-112df671cfc9c4c162793234f846b6d0R112
sure, i will make a pr in next week.
This is fixed in #240. Will be released in 0.7.2.
Ok, so I'm closing this issue. @mingyang91 feel free to reopen if the issue will still exist in 0.7.2.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.