graphql-engine: Hasura doesn't show RAISE EXCEPTION message from postgres function
It’s common to make some checks in triggers and RAISE NOTICE or EXCEPTION and provided message went to postgres log. Can we somehow provide this message to the client, instead poor Uncaught (in promise) Error: GraphQL error: postgres query error
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 37
- Comments: 25 (7 by maintainers)
I guess you can use Class 22 — Data Exception error codes
raise exception like this RAISE EXCEPTION USING ERRCODE= ‘22000’, MESSAGE= ‘business logic error message’;
and the client will always receive { “errors”: [ { “extensions”: { “path”: “$”, “code”: “data-exception” }, “message”: “business logic error message” } ] }
https://www.postgresql.org/docs/current/errcodes-appendix.html
@0x777 that would be great. It would also be helpful if that check support a prefix or a pattern/mask to be configured, this could be in accordance to what is specified in the documentation.
In our use case today, we have a helper function (example below) that raises all exceptions that we want to propagate to the client. We use a prefix (eg:
C0) to the code in order to indicate such application errors.It would really helpful if such a usage pattern (including the propagation of
HINT) could be supported in the solution for this issue.This is a must feature.We really need this feature. When it will be available?
It raises proper exceptions if you use hasura-admin-secret but will fail if you use jwt authorization.
Any update? I think this is really needed for any kind of serious app with validations.
use this code it’s work
for ERRCODE number you can only use in this list https://www.postgresql.org/docs/current/errcodes-appendix.html
Not sure this is needed anymore since you can set ERRCODE and that’ll cause the message to show. Awesome find, @sasog23!! Exactly what I was hoping for.
I’m not an expert here but I’m not sure NOTICE level messages could ever be passed through because of the way graphql clients expect responses. setting the
errorsfield signifies an error for a graphql client, and would probably throw.Maybe it would make sense to change the scope of this issue to target passing other exception info, like HINT and DETAILS.
It seems to be fixed in the last Hasura release https://github.com/hasura/graphql-engine/releases/tag/v1.2.0-beta.5 You have to put
HASURA_GRAPHQL_DEV_MODEastrueor start the server with--dev-modeflag.I’m wondering why they consider this a
devsetting while our usecase is pretty common ?@abn This is definitely something that we want to implement but we haven’t added it to our pipeline yet. Hopefully, we can get this out in a couple of releases.