webiny-js icon indicating copy to clipboard operation
webiny-js copied to clipboard

Authentication error returns an invalid GraphQL response

Open Pavel910 opened this issue 3 years ago • 2 comments

Version

5.13.0

What steps will reproduce the bug?

It's hard to reproduce, but it will happen if you have an expired JWT token. To force this bug, add an authentication plugin which throws an error. Any error will do. The goal is to abort processing of before-handler plugins, which goes straight into the catch block and into handler-error plugins.

What is the expected behavior?

The response should be formatted with { errors: [....] }, which is a valid GraphQL response.

What do you see instead?

Response is formatted as { error: { ... } }, which is something, but not a valid GraphQL response.

Additional information

image

Possible solution

Add a handler-error plugin to handler-graphql package, to format errors accordingly. Moreover, I suspect we'll need to reverse plugins before processing handler-error plugins, so that the last plugin registered is the first to be executed.

Error handling plugin should be added around here: packages/handler-graphql/src/createGraphQLHandler.ts:58

Pavel910 avatar Aug 26 '21 14:08 Pavel910

This issue is stale because it was opened 120 days with no activity. Remove the "stale-issue" label or leave a comment to revive the issue. Otherwise, it will be closed in 7 days.

webiny-bot avatar Feb 20 '22 07:02 webiny-bot

This issue is stale because it was opened 120 days with no activity. Remove the "stale-issue" label or leave a comment to revive the issue. Otherwise, it will be closed in 7 days.

webiny-bot avatar Jun 21 '22 07:06 webiny-bot