StrawHat v0.1.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.
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{}
to %StrawHat.Error.ErrorList{}
error
Returns a %StrawHat.Error{}
Link to this section Types
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
Converts an %Ecto.Changeset{}
to %StrawHat.Error.ErrorList{}
error.
Returns a %StrawHat.Error{}
.