Skip to content

Commit

Permalink
docs: error generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikFerrari committed May 17, 2024
1 parent bd04948 commit 7136d71
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/arke/utils/error_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@

defmodule Arke.Utils.ErrorGenerator do
@moduledoc """
Documentation for `Arke.Utils.ErrorGenerator`
"""

@doc """
Create standardized errors
## Parameters
- context => string => the context where the error has been generated
- errors => list | string => the error itself
Used to standardize all the arke package errors
## Example
iex> Arke.Utils.ErrorGenerator.create(:auth, "login error")
## Return
{:error , [%{context: "context_value", message: "message_value"}, ...]}
"""

@type t() :: {:error, [%{context: String.t(), message: String.t()}]}
@doc """
Create standardized errors.
## Note
- If a list of error is provided they will be created with the same context
- If a string is provided the above example will be returned
## Parameters
- `context` => the context where the error has been generated
- `errors` => the error itself
"""

@spec create(context :: String.t(), errors :: list() | String.t()) ::
@spec create(context :: String.t() | atom(), errors :: [String.t()] | String.t()) ::
{:error, [%{context: String.t(), message: String.t()}]}
def create(context, errors) when is_list(errors) do
{:error, create_map(context, errors)}
Expand Down

0 comments on commit 7136d71

Please sign in to comment.