Packages
sentry
11.0.4
13.3.0
13.2.0
13.1.0
13.0.1
13.0.0
12.0.3
12.0.2
12.0.1
12.0.0
11.0.4
11.0.3
11.0.2
11.0.1
11.0.0
10.10.0
10.9.0
10.8.1
10.8.0
10.7.1
10.7.0
10.6.2
10.6.1
10.6.0
10.5.0
10.4.0
10.3.0
10.2.1
10.2.0
10.2.0-rc.2
10.2.0-rc.1
10.1.0
10.0.3
10.0.2
10.0.1
10.0.0
9.1.0
9.0.0
8.1.0
8.0.6
8.0.5
8.0.4
8.0.3
8.0.2
8.0.1
8.0.0
8.0.0-rc.2
8.0.0-rc.1
8.0.0-rc.0
retired
7.2.5
7.2.4
7.2.3
7.2.2
7.2.1
7.2.0
7.1.0
7.0.6
7.0.5
7.0.4
7.0.3
7.0.2
7.0.1
7.0.0
6.4.2
6.4.1
6.4.0
6.3.0
6.2.1
6.2.0
6.1.0
6.0.5
6.0.4
6.0.3
6.0.2
6.0.1
6.0.0
5.0.1
5.0.0
4.0.3
4.0.2
4.0.1
4.0.0
3.0.0
2.2.0
2.1.0
2.0.2
2.0.1
2.0.0
1.1.2
1.1.1
1.1.0
1.0.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
The Official Elixir client for Sentry
Current section
Files
Jump to
Current section
Files
lib/sentry/client_error.ex
defmodule Sentry.ClientError do
@moduledoc """
An exception struct that represents an error returned by Sentry when
reporting an error or a message.
This struct is designed to manage and handle errors originating from operations
in the Sentry client. The `:reason` field contains the cause of the error
as an atom or tuple (see `t:reason/0`).
To raise instances of this exception, you can use `raise/1`. When crafting
formatted error messages for purposes such as logging or presentation, consider
leveraging `Exception.message/1`.
"""
@moduledoc since: "10.7.0"
@doc """
The exception struct for a Sentry error.
"""
defexception [:reason, :http_response]
@typedoc """
The type for a Sentry error exception.
"""
@type t :: %__MODULE__{
reason: reason(),
http_response:
nil | {status :: 100..599, headers :: [{String.t(), String.t()}], body :: binary()}
}
@typedoc """
The reason for a Sentry error exception.
"""
@type reason() ::
:too_many_retries
| :server_error
| {:invalid_json, Exception.t()}
| {:request_failure, reason :: :inet.posix() | term()}
| {Exception.kind(), reason :: term(), Exception.stacktrace()}
@doc false
@spec new(reason()) :: t
def new(reason) do
%__MODULE__{reason: reason}
end
@doc false
@spec server_error(status :: 100..599, headers :: [{String.t(), String.t()}], body :: binary()) ::
t
def server_error(status, headers, body) do
%__MODULE__{reason: :server_error, http_response: {status, headers, body}}
end
@impl true
def message(%__MODULE__{reason: reason, http_response: http_response}) do
"Sentry failed to report event: #{format(reason, http_response)}"
end
defp format(:server_error, {status, headers, body}) do
"""
the Sentry server responded with an error, the details are below.
HTTP Status: #{status}
Response Headers: #{inspect(headers)}
Response Body: #{inspect(body)}
"""
end
defp format(reason, nil) do
format(reason)
end
defp format(:too_many_retries) do
"Sentry responded with status 429 - Too Many Requests and the SDK exhausted the configured retries"
end
defp format({:invalid_json, reason}) do
formatted =
if is_exception(reason) do
Exception.message(reason)
else
inspect(reason)
end
"the Sentry SDK could not encode the event to JSON: #{formatted}"
end
defp format({:request_failure, reason}) do
"there was a request failure: #{format_request_failure(reason)}"
end
defp format({kind, data, stacktrace}) do
"""
there was an unexpected error:
#{Exception.format(kind, data, stacktrace)}\
"""
end
defp format_request_failure(reason) when is_binary(reason) do
reason
end
defp format_request_failure(reason) when is_atom(reason) do
case :inet.format_error(reason) do
~c"unknown POSIX error" -> inspect(reason)
formatted -> List.to_string(formatted)
end
end
defp format_request_failure(reason) do
inspect(reason)
end
end