Prevent exposing technical information through server error messages.
defmodule MyAppWeb.ErrorView do
use MyAppWeb, :view
def render("500.json", _assigns) do
%{errors: %{detail: 'Internal server error'}}
end
end
This code is insecure because it might reveal too much information in the error details when a server error (HTTP 500) occurs. Detailed error messages can potentially expose sensitive technical details about your system.
defmodule MyAppWeb.ErrorView do
use MyAppWeb, :view
def render("500.json", _assigns) do
%{errors: %{detail: 'An error occurred. We are working to fix it.'}}
end
end
This code is secure because it uses a generic error message to indicate a server error, without revealing any technical details. The detailed error information is not exposed to the client, reducing the risk of information leaks.