cube icon indicating copy to clipboard operation
cube copied to clipboard

Returning custom HTTP error codes from `check_auth`

Open spljs opened this issue 3 months ago • 2 comments

Is your feature request related to a problem? Please describe. Return an appropriate response code or even a custom one in the checkAuth function

Describe the solution you'd like Expose the res object to manipulate it , or return a 401 http response code

Additional context

module.exports = {
    checkAuth: async (req) => {
        const token = extractJwt(req);
        req.securityContext = await validateAndParseJwt(token);
        throw new Error("test"); // this causes cube to return http 500
    }
}

spljs avatar Apr 12 '24 07:04 spljs

If you are interested in working on this issue, please provide go ahead and provide PR for that. We'd be happy to review it and merge it. If this is the first time you are contributing a Pull Request to Cube, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube Slack.

github-actions[bot] avatar Apr 12 '24 10:04 github-actions[bot]

Hi @spljs 👋 I think this makes a lot of sense!

I believe that the solution to this should work equally well with JavaScript-based and Python-based configuration. So, exposing the res object is less desirable than, say, providing a custom Error/Exception type to raise/throw.

igorlukanin avatar Apr 12 '24 10:04 igorlukanin