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

New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
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
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

Other popular topics Top

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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement