gmc
I’ve created a JSON API and deconstruct parameters in the controller action like this:
def create(conn, %{“item” => item_params}) do
…
end
Now I’d like to capture the cases where the pattern isn’t matched (e.g. not having the “item” in the request JSON) and send an appropriate error JSON.
How can this be done? Now I just get “no function clause matching in …create/2” error. After some research I found the following issue which would suit my needs, but it was closed by José:
https://github.com/phoenixframework/phoenix/issues/2386
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nicd
Write a second clause for the function:
gmc
I actually thought about this, but then I asked me, how can Elixir know which function to take for a valid request? In that case both functions would match, right? How is the priority handled in Elixir? Sorry, this is a very basic question as I’m new to Elixir/Phoenix…
stefanchrobot
The pattern matching is applied top to bottom:
gmc
Ah, thanks for this, that’s essential to know!
Sebb
I just wanted to point to the documentation about pattern matching in functions, but there seems to be none. Neither in elixir-hexdocs nor in the guide…? Am I missing something?
stefanchrobot
How about https://elixir-lang.org/getting-started/pattern-matching.html
EDIT: oh, I see. There’s no mention of pattern matching in function heads.
Sebb
There is sth here Functions · Elixir School
But its not part of the official docs.
adamu
I am also confused by this.
José Valim here:
Chris McCord here:
The phoenix docs:
However, in all the examples provided above and in the linked GitHub issues, and in my test, the error is not handled by Phoenix, the
Plug.Exceptionprotocol is unused, and the program crashes with the uncaught exception (a generic 500 error is thrown if accessing via the browser, exception is uncaught in tests).Is something supposed to catch these
Plug.Exceptionexceptions and route them to theErrorView, or is this only for debugging?LostKobrakai
It works fine for me here:
https://github.com/LostKobrakai/repo_exception/commit/550e60c29d5764dbfd3e07a9cf0d2465a4f7c4fe
One thing to note is that the
Phoenix.ConnTestAPI is not meant to catch exceptions as they skip the outer http parts of handling a request. You also generally want the exceptions details in tests to be able to debug issues. Other frameworks usually need code to disable that.You can test
Plug.Exceptionworking though by enabling the server in the test env and doing full http requests.adamu
Thank you!
ConnTestbehaving differently to HTTP requests was tripping me up, thanks for pointing that out - and for the demo. Super helpful.