Errors
KScript.Data throws errors you can catch by type. In a route, each one becomes a sensible HTTP status for you:
ModelNotFound, a kind ofNotFound, comes from->find_or_fail()and->first_or_fail().$e.modeland$e.idsay what wasn't found. A route answers 404.UniqueViolation, a kind ofConflict, means a save would give two records the same unique value.$e.fieldsnames the fields. A route answers 409.ForeignKeyViolation, also aConflict, means a change would leave a row pointing at one that isn't there. A route answers 409.Querymeans the database refused a query, or a condition can't be turned into SQL. A route answers 500.MultipleRecordsFound, a kind ofQuery, comes from->sole()when more than one row matches.Connectionmeans the database can't be opened. A route answers 503.
<try>
<do>User->create(email: 'ada@example.com')</do>
<catch type="UniqueViolation" as="e">
<echo>That email is already taken.</echo>
</catch>
</try>try {
User->create(email: 'ada@example.com')
} catch UniqueViolation as e {
echo "That email is already taken."
}