Commit 0179d773 authored by Mikko Ahlroth's avatar Mikko Ahlroth

Enable JSON errors for better debugging

parent d9419296
......@@ -3,7 +3,7 @@ defmodule CodeStats.Mixfile do
def project do
[app: :code_stats,
version: "1.3.1",
version: "1.3.2",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
......
......@@ -17,7 +17,7 @@ defmodule CodeStats.PulseController do
def add(conn, %{"coded_at" => timestamp, "xps" => xps}) do
if not is_list(xps) do
resp(conn, 400, "Invalid xps format.")
resp(conn, 400, %{error: "Invalid xps format."})
end
case do_add(conn, timestamp, xps) do
......@@ -27,13 +27,13 @@ defmodule CodeStats.PulseController do
|> json(%{"ok" => "Great success!"})
{:error, :not_found, reason} ->
resp(conn, 404, reason)
resp(conn, 404, %{error: reason})
{:error, :generic, reason} ->
resp(conn, 400, reason)
resp(conn, 400, %{error: reason})
{:error, :internal, reason} ->
resp(conn, 500, reason)
resp(conn, 500, %{error: reason})
end
end
......
......@@ -32,7 +32,7 @@
<h4>Protocol</h4>
<p>
All requests are made using the HTTP protocol and use JSON to serialize the data. Requests with payloads should send the payload as JSON in the request body. Error responses from the server will only return the error string, so if the response code is not in the 2xx series, don't attempt to parse the content as JSON.
All requests are made using the HTTP protocol and use JSON to serialize the data. Requests with payloads should send the payload as JSON in the request body. The responses are JSON, error responses will contain the key <code>error</code> which has the error message as value.
</p>
<h4>Path</h4>
......
......@@ -24,6 +24,14 @@
<h2>Changelog</h2>
<h3>1.3.2 – 2016-06-06 – JSON errors</h3>
<p>
<ul>
<li>Enabled JSON errors for easier debugging of 500 Internal server errors.</li>
</ul>
</p>
<h3>1.3.1 – 2016-06-05 – Language name fix</h3>
<p>
......
......@@ -12,6 +12,10 @@ defmodule CodeStats.ErrorView do
"""
end
def render("404.json", _assigns) do
%{error: "Route not found."}
end
def render("500.html", _assigns) do
raw """
<div class="jumbotron">
......@@ -23,6 +27,10 @@ defmodule CodeStats.ErrorView do
"""
end
def render("500.json", _assigns) do
%{error: "The server some kind of exploded."}
end
def render("403.html", _assigns) do
raw """
<div class="jumbotron">
......@@ -34,6 +42,10 @@ defmodule CodeStats.ErrorView do
"""
end
def render("403.json", _assigns) do
%{error: "You are not allowed to do that."}
end
# In case no render clause matches or no
# template is found, let's render it as 500
def template_not_found(_template, assigns) do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment