feat: improve phoenix errors#2029
Conversation
CRAP Score Report |
leandrocp
left a comment
There was a problem hiding this comment.
Just non-blocking suggestions.
| defp status_code(status) when is_integer(status), do: status | ||
| defp status_code(status), do: Plug.Conn.Status.code(status) | ||
|
|
||
| defp format_reason(_kind, %mod{__exception__: true} = reason), |
There was a problem hiding this comment.
Old habit of matching __exception__? Nitpick but you could use https://elixir.hexdocs.pm/Kernel.html#is_exception/1 😄
| assert log =~ "[error]" | ||
| assert log =~ "HttpServerError" | ||
| assert log =~ "Sent 500 response: RuntimeError - boom" |
There was a problem hiding this comment.
Nitpick but we could do a single assert to avoid false positives:
| assert log =~ "[error]" | |
| assert log =~ "HttpServerError" | |
| assert log =~ "Sent 500 response: RuntimeError - boom" | |
| assert log =~ "error_code=HttpServerError [error] HttpServerError: Sent 500 response: RuntimeError - boom" |
| defp status_code(status) when is_integer(status), do: status | ||
| defp status_code(status), do: Plug.Conn.Status.code(status) |
There was a problem hiding this comment.
| defp status_code(status) when is_integer(status), do: status | |
| defp status_code(status), do: Plug.Conn.Status.code(status) |
https://github.com/supabase/realtime/pull/2029/changes#r3596892449
| status = status_code(status) | ||
| message = "Sent #{status} response: #{format_reason(kind, reason)}" |
There was a problem hiding this comment.
Plug.Conn.Status.code/1 already checks if value is integer.
| status = status_code(status) | |
| message = "Sent #{status} response: #{format_reason(kind, reason)}" | |
| message = "Sent #{Plug.Conn.Status.code(status)} response: #{format_reason(kind, reason)}" |
| defp error_response(:token_malformed), do: {401, "The token provided is not a valid JWT"} | ||
| defp error_response(:too_many_connections), do: {429, "Too many connected users"} | ||
| defp error_response(:too_many_joins), do: {429, "Too many joins per second"} | ||
| defp error_response(_reason), do: {403, "Error connecting to Realtime"} |
There was a problem hiding this comment.
Forbidden as a default reason seems wrong 🤔
| end | ||
| end | ||
|
|
||
| describe "handle_error/2" do |
There was a problem hiding this comment.
can we get integration tests for a few of these?
a2f450d to
7129575
Compare
|
🎉 This PR is included in version 2.116.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
What kind of change does this PR introduce?
improve phoenix errors to show more information and give them more relevance