AUGERClement
API raise exception instead of returning []
Hello.
I am fairly new to Phoenix/elixir, but I read the doc and couldn’t find what I was looking for.
I am currently working on a basic Phoenix API. After studying a bit the Ecto documentation, I found the lines about Ecto.get and get_by, which helped me adding new endpoints to request the database with another argument than the id.
Now, I am stuck, because when I request some id which isn’t on the API, it raise a error " Ecto.NoResultsError". What I want is a empty data, or nil, so my other program can check if there is content matching the request.
I undestand the Exception came from the Repo.get, so I tried to rewrite my show function in the controller like that :
def show(conn, %{"accession_number" => accession_number}) do
try do
dicom = DICOM.get_dicom_an!(accession_number)
render(conn, "show.json", dicom: dicom)
rescue
e in RuntimeError -> IO.puts(e.message)
render(conn, "show.json", "")
end
end
However, I couldn’t get it to work. I also tried to pattern match
with error in the delete function, but I couldn’t make it work.
What is the way to achieve what I want ?
Most Liked
AUGERClement
Ok, I get the error, it something I’ve looked up.
What I don’t undestand is why it happen in that case, what can I do, and why does the whole work when I use a valid id.
I checked my PostGRES and my id column is of type uuid (autogenerated). My exception also said :
value `"b416bab4-e526-49cd-8109-45aed0baee3"` cannot be dumped to type :binary_id in query:
So, I think I am not using an integer id. What am I missing ?
Popular in Questions
Other popular topics
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










