moxley

moxley

Using Ash.Query.add_error()

I’m creating a read AshGraphql query, and I want it to return an error for certain conditions. When I call Ash.Query.add_error(query, "some error message") or similar in the action prepare, the GraphQL query returns:

%{
  "data" => %{"listMemberSelfSubscriptions" => nil},
  "errors" => [
    %{
      "locations" => [%{"column" => 3, "line" => 2}],
      "message" => "Something went wrong. Unique error id: `dd416b26-3ffd-4731-aae3-279a2131cb05`",
      "path" => ["listMemberSelfSubscriptions"]
    }
  ]
}

It always returns a generic “Something went wrong”. How do I pass an error message to the response?

If I use raw Ash.Query without AshGraphql, calling Ash.Query.add_error() results in an UnknownError:

 %Ash.Error.Unknown{
   errors: [
     %Ash.Error.Unknown.UnknownError{
       error: ": Test error",
       field: nil,
       value: nil,
       splode: Ash.Error,
       bread_crumbs: [],
       vars: [],
       path: [],
       stacktrace: #Splode.Stacktrace<>,
       class: :unknown
     }
   ]
 }

For that matter, how do I use Ash.Query.add_error()? There’s no documentation for it:

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

Ahh, that doc is out of date for 3.0, sorry! Using exception modules like that is “the way”, the only difference is that all our errors are exceptions, so you’d use .exception as if it was any other error. It’s all powered by the library (which was extracted out of Ash) called Splode API Reference — splode v0.3.1

Then, these errors have a specific protocol defined for them to allow them to be exposed over an API (differs depending on the API). You can also define your own errors and use those, if you implement the appropriate protocol.

You can see examples here: ash_graphql/lib/error.ex at main · ash-project/ash_graphql · GitHub

Also Liked

zachdaniel

zachdaniel

Creator of Ash

Since a release was just done yesterday, I was able to publish these new docs, so the hexdocs for Ash should reflect these updates as of now.

moxley

moxley

That’s great to hear! I’ll keep an eye our for opportunities to pitch in with some documentation PRs.

allenwyma

allenwyma

thank you for the recognition. Still trying to squeeze in time for docs!

Last Post!

allenwyma

allenwyma

thank you for the recognition. Still trying to squeeze in time for docs!

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement