Joe Eifert
Joe Eifert

Reputation: 1387

Elixir Phoenix: How to get 500 error information and notify admins

I want to get a telegram message / email whenever one of my customers manages to create a server error. Because that usually means that we created a bug and need to fix it asap. I also want the customers to be able to go back to where they came from, so I want to display a javascript go back button.

How do I go about that?

The button could look something like this:

<button onclick="window.history.back()">Back</button>

And notifying the admins like this:

for id <- Application.get_env(:nadia, :admin_chat_ids) do
  message = "#{error information like stacktrace and user information}"
  Nadia.send_message(id, message)
end

Where can I override the default behavior of phoenix and get the necessary information?

Upvotes: 1

Views: 599

Answers (1)

zhisme
zhisme

Reputation: 2800

You can use rollbar for example, it will send emails every-time you get new error, or repeatedly error, you can configure it on there UI.

in order to connect rollbar to your phoenix application, you would need rollbax gem it is wrapper for elixir library.

installation

defp deps() do
  [{:rollbax, ">= 0.0.0"}]
end

And add to your config. Your token will be available through the site after you create project.

config :rollbax,
  access_token: "YOUR_TOKEN",
  environment: "production"

And for using it inside Phoenix you would need to use it as Plug

defmodule MyApp.Router do
  use Plug.Router # or `use MyApp.Web, :router` for Phoenix apps
  use Plug.ErrorHandler

  defp handle_errors(conn, %{kind: kind, reason: reason, stack: stacktrace}) do
    Rollbax.report(kind, reason, stacktrace)
  end
end

Phoenix rollbax configuration

Upvotes: 2

Related Questions