Skip to content

Commit

Permalink
Add DBConnection.ConnectionError.t/0 type (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide authored Jan 5, 2024
1 parent fa5f705 commit 8ef1f2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
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

0 comments on commit 8ef1f2e

Please sign in to comment.