Skip to content

GraphQL Validation Errors sometimes returned as Internal Server Error #21264

@rijkvanzanten

Description

@rijkvanzanten
Member

Describe the Bug

When your mutation fails the GraphQL validation, the error is returned as an internal server error, which in turn means that non-admin users don't get to see the validation error message.

See #17035 (reply in thread)

To Reproduce

Try performing a mutation with a wrong payload in the GraphQL endpoint

Directus Version

10.8.3

Hosting Strategy

Self-Hosted (Docker Image)

Activity

Romakita

Romakita commented on Jan 31, 2024

@Romakita
Contributor

We can add more details:

Based on this file:

code: 'INTERNAL_SERVER_ERROR',

The issue concern also an Admin user. For the returned object response, it'll see INTERNAL_SERVER_ERROR.

A non-admin will always have INTERNAL_SERVER_ERROR in the response.

In both cases, the log will show an INTERNAL_SERVER_ERROR instead of having GRAPHQL_VALIDATION.

See you :)

dp1194

dp1194 commented on Feb 28, 2024

@dp1194

This seems to apply to the REST API as well and, in particular, affecting hooks.

So if you have a hook that does validation, as shown here, non-admin users don't see the validation error, they just see Internal Server Error. That's when saving from the App UI.

dp1194

dp1194 commented on Feb 28, 2024

@dp1194

I can't be sure if this is related or not but this is what I found that may be of help.

There is an error-handler middleware that seems to be responsible for this behaviour (as far as I understand from this issue and the one linked).
https://github.com/directus/directus/blob/main/api/src/middleware/error-handler.ts#L30

The middleware purposefully redacts the error message if the user is not an admin user but only if the error is not a Directus error.

My solution was to throw a Directus error as described here and indicated by the middleware above, rather than an http-error (or I guess any other type of error) as I was doing.

I think, for me, the confusion came in because you can throw an http-error in a custom endpoint extension and you'll always get the 400 response with message (although that might still not work for GraphQL). This seemed to work for hooks as well but only because I was testing with an admin user.

Also, last time I looked at this I didn't notice the error package documentation and struggled to get something like throw new ValidationException('This is invalid because...'); and so fell back to using http-error. So thanks for all the work and updates around this! I would still suggest having some explicit extension docs around this behaviour rather than in Extensions/Resources/Packages/@directus/errors. That might make it a bit clearer as to what's going on.

dp1194

dp1194 commented on Feb 28, 2024

@dp1194

We can add more details:

Based on this file:

code: 'INTERNAL_SERVER_ERROR',

The issue concern also an Admin user. For the returned object response, it'll see INTERNAL_SERVER_ERROR.

A non-admin will always have INTERNAL_SERVER_ERROR in the response.

In both cases, the log will show an INTERNAL_SERVER_ERROR instead of having GRAPHQL_VALIDATION.

See you :)

I wonder what's the relationship between directus/api/src/services/graphql/utils/process-error.ts and directus/api/src/middleware/error-handler.ts? Are these completely unrelated?

I reported a similar bug at the end of last year which I've only seen today that it's been resolved here.
#20442

The version of process-error linked above is a bit outdated. Looking at the latest version, it looks to be in alignment with the REST middleware.
https://github.com/directus/directus/blob/main/api/src/services/graphql/utils/process-error.ts

I'd say this bug is resolved @rijkvanzanten. Again, only thing I could suggest improving is the docs.

2 remaining items

self-assigned this
on May 9, 2025
linked a pull request that will close this issue on May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @Romakita@rijkvanzanten@Nitwel@licitdev@dp1194

    Issue actions

      GraphQL Validation Errors sometimes returned as Internal Server Error · Issue #21264 · directus/directus