Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

koa server always responds 404 #210

Closed
mingyang91 opened this issue Jul 13, 2017 · 7 comments
Closed

koa server always responds 404 #210

mingyang91 opened this issue Jul 13, 2017 · 7 comments
Assignees
Labels
type: fix Issues describing a broken feature.

Comments

@mingyang91
Copy link
Contributor

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

@MichalLytek
Copy link
Contributor

Could you make a PR and test the changes? 😉

@smithdalec
Copy link

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.

@MichalLytek
Copy link
Contributor

MichalLytek commented Aug 6, 2017

@mingyang91 Will you find some time to make a PR as you described the problem and found the fix?
mingyang91@38a68e6#diff-112df671cfc9c4c162793234f846b6d0R112

@MichalLytek MichalLytek added type: fix Issues describing a broken feature. help wanted labels Aug 6, 2017
@mingyang91
Copy link
Contributor Author

sure, i will make a pr in next week.

@NoNameProvided
Copy link
Member

This is fixed in #240. Will be released in 0.7.2.

@NoNameProvided NoNameProvided self-assigned this Aug 7, 2017
@MichalLytek
Copy link
Contributor

Ok, so I'm closing this issue. @mingyang91 feel free to reopen if the issue will still exist in 0.7.2.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: fix Issues describing a broken feature.
Development

No branches or pull requests

4 participants