krishna_vaguelyright
How to handle errors centrally?
How to handle errors centrally?
In my local instance, it throws the error with proper error codes. On prod deployed to fly, it just throws a 500 status error.
In my tests I have to use assert_error_sent to make tests pass. When i try to assert conn.status it just throws an error in test module.
conn = post(conn, `route`, %{})
assert conn.status == 400
This is what my code looks like… works fine in dev locally but throws 500 error in prod.
defmodule KayaanPrintsWeb.Router do
use KayaanPrintsWeb, :router
use Plug.ErrorHandler
require Logger
@impl true
def handle_errors(conn, %{kind: kind, reason: reason, stack: stack}) do
error_string = log_error_string(kind, reason, stack, conn)
case reason do
%Phoenix.Router.NoRouteError{} ->
Logger.error(error_string)
conn
|> put_status(:not_found)
|> json(%{error: "Route not found"})
|> halt()
....other error cases handling
Most Liked
LostKobrakai
If your test fails your code has a problem.
This likely works in dev, because phoenix enables Plug.Debugger in development. There can only ever be one error handler though, so your Plug.ErrorHandler might not even run.
1
Popular in Questions
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New







