From a17e4c198203abb231f1bd4eb890bf126da1740c Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Fri, 5 Jan 2024 15:45:00 +0100 Subject: [PATCH] Add DBConnection.ConnectionError.t/0 type --- lib/db_connection/connection.ex | 18 ------------------ lib/db_connection/connection_error.ex | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 lib/db_connection/connection_error.ex diff --git a/lib/db_connection/connection.ex b/lib/db_connection/connection.ex index bc0bbba..48ecdad 100644 --- a/lib/db_connection/connection.ex +++ b/lib/db_connection/connection.ex @@ -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 diff --git a/lib/db_connection/connection_error.ex b/lib/db_connection/connection_error.ex new file mode 100644 index 0000000..0c98ec8 --- /dev/null +++ b/lib/db_connection/connection_error.ex @@ -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