question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hasura doesn't show RAISE EXCEPTION message from postgres function

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:37
  • Comments:25 (7 by maintainers)

github_iconTop GitHub Comments

26reactions
sasog23commented, Oct 9, 2020

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

9reactions
abncommented, Sep 15, 2019

@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.

When specifying an error code by SQLSTATE code, you are not limited to the predefined error codes, but can select any error code consisting of five digits and/or upper-case ASCII letters, other than 00000. It is recommended that you avoid throwing error codes that end in three zeroes, because these are category codes and can only be trapped by trapping the whole category.

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.

CREATE FUNCTION errors.raise(
  code_    TEXT DEFAULT 'C0500',
  message_ TEXT DEFAULT 'Something went wrong while processing your request',
  hint_    TEXT DEFAULT 'Try again later'
) RETURNS VOID
  LANGUAGE plpgsql
  IMMUTABLE STRICT PARALLEL SAFE AS
$function$
BEGIN
  RAISE EXCEPTION USING ERRCODE = code_, MESSAGE = message_, HINT = hint_;
END;
$function$;

It would really helpful if such a usage pattern (including the propagation of HINT) could be supported in the solution for this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling GraphQL Errors with Hasura & React
A guide to common GraphQL API & Hasura specific errors and how to handle them with React pages.
Read more >
Top GraphQL Errors and How to fix them
Identifying error types will help quickly fix them. Clients can encounter these types of errors while communicating with the GraphQL server.
Read more >
Postgres: Data validations | Hasura GraphQL Docs
We can now create a Postgres function that checks if an article's content exceeds a certain ... RAISE EXCEPTION 'Content can not have...
Read more >
Postgres: Filter query results / search queries - Hasura
Filter query results and search queries on Postgres in Hasura. ... By design, the _eq or _neq operators will not return rows with...
Read more >
Optimizing your GraphQL API with Postgres - Hasura
This post shows how to optimize your GraphQL API using some of Postgres' most popular features. These will help with data validations, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found