Skip to content

Commit

Permalink
Create fallback controller
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmp07 committed Oct 19, 2021
1 parent 7071ed0 commit e37d258
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/inmana_web/controllers/fallback_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule InmanaWeb.FallbackController do
use InmanaWeb, :controller

alias InmanaWeb.ErrorView

def call(connection, {:error, %{result: result, status: status}}) do
connection
|> put_status(status)
|> put_view(ErrorView)
|> render("error.json", result: result)
end
end
4 changes: 4 additions & 0 deletions lib/inmana_web/controllers/restaurants_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ defmodule InmanaWeb.RestaurantsController do
alias Inmana.Restaurant
alias Inmana.Restaurants.Create

alias InmanaWeb.FallbackController

action_fallback FallbackController

def create(connection, params) do
with {:ok, %Restaurant{} = restaurant} <- Create.call(params) do
connection
Expand Down

0 comments on commit e37d258

Please sign in to comment.