View Source StrawHat.Error (StrawHat v0.6.2)
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
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.
Functions
Converts an Ecto.Changeset.t/0 to StrawHat.Error.ErrorList.t/0 error.
Returns a StrawHat.Error.t/0.
Link to this section Types
Specs
Specs
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
Specs
new(Ecto.Changeset.t()) :: StrawHat.Error.ErrorList.t()
Converts an Ecto.Changeset.t/0 to StrawHat.Error.ErrorList.t/0 error.
Specs
Returns a StrawHat.Error.t/0.