Skip to content

Instantly share code, notes, and snippets.

@jorgevilaca82
Created October 9, 2024 14:52
Show Gist options
  • Save jorgevilaca82/afac7f88bb435920b9e0b7c7954dbaaa to your computer and use it in GitHub Desktop.
Save jorgevilaca82/afac7f88bb435920b9e0b7c7954dbaaa to your computer and use it in GitHub Desktop.
Error module
defmodule Error do
defstruct code: nil, message: nil, details: nil
@doc """
Creates a new error struct
## Usage:
iex> Error.new("E001", "This is an error")
or with opts:
iex> Error.new("E001", "This is an error", details: [id: "XPTO-001"])
"""
def new(code, message, opts \\ []) do
%__MODULE__{code: code, message: message}
|> struct(opts)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment