Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DBConnection.ConnectionError.t/0 type #304

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions lib/db_connection/connection.ex
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
defmodule DBConnection.ConnectionError do
defexception [:message, severity: :error, reason: :error]

@moduledoc """
A generic connection error exception.

The raised exception might include the reason which would be useful
to programmatically determine what was causing the error.
"""

@doc false
def exception(message, reason) do
message
|> exception()
|> Map.replace!(:reason, reason)
end
end

defmodule DBConnection.Connection do
@moduledoc false

Expand Down
24 changes: 24 additions & 0 deletions lib/db_connection/connection_error.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule DBConnection.ConnectionError do
@moduledoc """
A generic connection error exception.

The raised exception might include the reason which would be useful
to programmatically determine what was causing the error.
"""

@typedoc since: "2.7.0"
@type t() :: %__MODULE__{
message: String.t(),
reason: :error | :queue_timeout,
severity: Logger.level()
}

defexception [:message, severity: :error, reason: :error]

@doc false
def exception(message, reason) when is_binary(message) and reason in [:error, :queue_timeout] do
message
|> exception()
|> Map.replace!(:reason, reason)
end
end
Loading