niccolox
I am trying to create a Phoenix controller action that allows conn to fall through action if the parameter is not matched by a query.
i.e. if there is no user the conn passes through this action and gets caught by another controller
I am getting an error 500.
What am I missing?
def pass_action(conn, %{"id" => id}) do
user = Repo.get_by(User, slug: id)
if user != nil do
user = Repo.get_by!(User, slug: id)
render(conn, "show.html",
user: user)
else
conn
end
end
this status 500
00:20:16.059 [error] #PID<0.23653.0> running WwwAppCom.Web.Endpoint (connection #PID<0.21719.0>, stream id 13) terminated
Server: local.app.com:4000 (http)
Request: GET /usr
** (exit) an exception was raised:
** (Plug.Conn.NotSentError) a response was neither set nor sent from the connection
(phoenix 1.5.8) lib/phoenix/endpoint/cowboy2_handler.ex:110: Phoenix.Endpoint.Cowboy2Handler.maybe_send/2
(phoenix 1.5.8) lib/phoenix/endpoint/cowboy2_handler.ex:66: Phoenix.Endpoint.Cowboy2Handler.init/4
(cowboy 2.8.0) /deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.8.0) /deps/cowboy/src/cowboy_stream_h.erl:300: :cowboy_stream_h.execute/3
(cowboy 2.8.0) /deps/cowboy/src/cowboy_stream_h.erl:291: :cowboy_stream_h.request_process/3
(stdlib 3.12.1) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
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
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
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
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
matthieuchabert
Hi,
In a controller, you need to send a response back to the client. For example, your
show.htmltemplate, a 404, a redirect, etc.If I understand correctly you would want to use a redirect:
redirect(conn, to: "/your-other-controller")instead of justconn.I hope it fixes your issue.
LostKobrakai
That’s not possible with the existing router implemenations. Once a controller was matched by the router the request is neither going back into the router, nor could the router match a later controller, as routers work with pattern matching behind the scenes. The beam does not expose means of “skipping” such a match.
axelson
I believe you can accomplish what you want with a fallback controller: Phoenix.Controller — Phoenix v1.8.8
niccolox
thanks @matthieuchabert @LostKobrakai @axelson
I will investigate this very helpful information