How do I create an error struct directly, as part of an {:error, error} tuple? For example, I have a Changeset.after_action() that needs to return an error for a not-found case, and an error for an unauthorized case. What is the correct way to specify those kinds of errors? Also, I want the error to show up in an AshGraphql response.
There is also an AshGraphql specific guide on errors here Handling Errors — ash_graphql v1.7.2 that has an example of defining a custom exception that can be rendered in the GraphQL response.
We should add descriptions of the fields, or @type t to those exceptions, but if you click into the source its easy enough to see what fields can be provided:
use Splode.Error, fields: [:primary_key, :resource]
creating a custom exception would allow you to customize exactly how its represented in AshGraphql and what fields can be provided.
I think I understand now. The exception() function on the error modules takes a keyword list, even though the documentation for exception() shows it taking zero arguments. There is an example in the Error Handling page that shows calling Ash.Error.Changes.Required.exception() with a keyword list, and I wasn’t able to extrapolate that to the exception() functions on the other error modules. Now I understand. Thanks