SnowySailor

SnowySailor

Flash message persistance seems to only work with a 302

I’m working on getting some flash messages to appear correctly after a failed captcha. I have a CaptchPlug that will validate the captcha and if the user gets it wrong or there was some error with the verification process, it’ll put a flash message up telling the user what happened.

I have this code here that runs on failure:

conn
        |> Controller.put_flash(
          :error,
          "There was an error verifying you're not a robot. Please try again."
        )
        |> Conn.put_status(:conflict)
        |> Controller.text("")
        |> Conn.halt()

The client side code makes a JS http request to an endpoint and it will get back a 409 (conflict) and trigger a page reload. I expect the reloaded page to show the flash message. However when the page reloads, there’s no message to be seen. BUT when I change the put_status to return a 302 instead, I can do the exact same thing as I did with the 409 (without the browser reloading itself) and reload the page and the flash message appears. The only difference between the two tests is a 409 vs. a 302 status code (browser is performing the exact same requests either way), but the message doesn’t appear unless I use a 302.

Is there some logic that surrounds flash messages and status codes? Is there a better way to get at what I’m trying to do?

Thanks

Marked As Solved

LostKobrakai

LostKobrakai

Only 3xx status codes will put the flash message in the session. All other ones are meant to render the flash message within the request, which set the flash message.

Where Next?

Popular in Questions Top

chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43806 214
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement