lud
Hello,
By default Phoenix will generate this on a new project:
# def render("500.json", _assigns) do
# %{errors: %{detail: "Internal Server Error"}}
# end
def render(template, _assigns) do
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
end
Not sure if it is because of an english thing (not my native language) but to me it seems that a map would describe a single error ; plus we are giving the detail for one error.
When I’ll have multiple errors, on an Ecto changeset for instance, I’ll generally return something like that:
%{
error: %{
message: "Invalid Request",
detail: %{
errors: [] # ... changeset errors as a list
}
}
}
Or maybe something like this:
%{
errors: [
%{
message: "Invalid Request",
detail: [] # ... changeset errors as a list
}
]
}
But I don’t understand the default layout, which is one of the first things I change on a new project.
What is the rationale behind this?
Thank you.
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
The obligatory hello world thread!
Who are you and where are you from? :stuck_out_tongue:
New
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using.
We’re particularly inte...
New
Is there a word for the ~> symbol used in Version strings?
Do you also just call it a Squiggle Arrow™ ?!
New
I’m posting this in response to Jose’s recent tweet (Cr. link) :
People are sleeping on Elixir for a coding harness:
Hot-code swappi...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lud
@chrismccord Maybe you can shed some light on this!
jdiago
You sort of answered your own question.
Code gen is only there to get someone started. It’ll never be 100% correct for all use cases and it’s almost never the code that ends up in production. It’s not a crime to change the code generators give you.
As a last resort, you can also make your proposed changes to the generator and open a PR to see if it’ll get accepted.
lud
Hello,
Well I’m asking what is the rationale beyond those choices. Of course I can change it.
My problem here is that is has been correct for 0% use cases in my experience. We always changed it. I wonder why the current layout was chosen.
LostKobrakai
I’d propose a PR changing it to something more useful then. To me this doesn’t look like a very intentional format.
jdiago
I dug a little deeper and this is my speculation:
This bit is in the
MyApp.ErrorJSONmodule.When you use
mix phx.gen.json, you will get aresource_json.exwhich will have the following:Seems to me like lud’s suggested change is supposed to go into a controller’s JSON module.
Notice the matching
:errorsroot key. That probably makes it easier for API clients to handle errors no matter where it’s coming from (an action on a resource or somewhere up the plug chain)LostKobrakai
Ecto.Changeset.traverse_errors/2returns a list though. Not a single object.jdiago
errors: [...]makes it grammatically correct.If an error comes from somewhere up the plug chain,
MyApp.ErrorJSONis used which will return{errors: ...}. If the error is on a create or update action, the resource’s JSON module will also return{errors: ...}.That would mean that I, as the API consummer, would only have to worry about handling 1
errorsroot key instead of handling botherroranderrors.lud
But you would not know if its a list or an object. Hence the second “correct” example I gave where errors is always a list.