I’m the backend developer on a graphql/absinthe project, and the front end dev would like to have custom codes added to ALL error responses, including syntax errors. This failed test output illustrates what I’m envisioning:
1) test malformed request (missing closing `}`) includes 422 status code (MyAppWeb.Schema.Mutation.LoginTest)
test/my_app_web/schema/mutation/login_test.exs:51
match (=) failed
code: assert %{"errors" => [%{"status_code" => 422}]} = json_response(response, 200)
left: %{"errors" => [%{"status_code" => 422}]}
right: %{"errors" => [%{"locations" => [%{"column" => 0, "line" => 4}], "message" => "syntax error before: "}]}
I’m able to add a custom “status_code” to errors inside middleware, but syntax errors and errors of requesting undefined schema fields are returned before any middleware, I’m guessing in the asbinthe plug. How can I added a custom “status_code” to these types of errors? Is it ill-advised?
Thank you!