StrawHat v0.6.0 StrawHat.Error View Source

Used for Error handling. The StrawHat's philosophy is to have data structure as much as we can.

Usage

One example of the struct could be with Ecto. When you want to find some record but it does not exists on the database.

Examples

case Repo.get(UserSchema, id) do
  nil -> {:error, StrawHat.Error.new("user.not_found", metadata: [user_id: id])}
  user -> {:ok, user}
end

Link to this section Summary

Types

t()
  • id: Unique identifier setup by the System. Used for tracking, it's unique per instance of the Error. Default: UUID.uuid1().
  • code: Represent the ID defined by your system designed. Example: "straw_hat.validation.required"
  • type: Categorize/Group your errors. Default "generic".
  • metadata: A set of key value with useful information about the error.

Link to this section Types

Link to this type

opts()

View Source
opts() :: [type: String.t(), metadata: Keyword.t()]
Link to this type

t()

View Source
t() :: %StrawHat.Error{
  code: String.t(),
  id: String.t(),
  metadata: [StrawHat.Error.ErrorMetadata.t()],
  type: String.t()
}
  • id: Unique identifier setup by the System. Used for tracking, it's unique per instance of the Error. Default: UUID.uuid1().
  • code: Represent the ID defined by your system designed. Example: "straw_hat.validation.required"
  • type: Categorize/Group your errors. Default "generic".
  • metadata: A set of key value with useful information about the error.

Link to this section Functions