Errors

Errors are answered in JSON, with a stable code to match on:

{ "code": "ENTITY_NOT_FOUND", "message": "no entity has this id" }
Status code When
400 ID_MISMATCH The primary key of the PUT payload (id by default) differs from the id of the path
400 BAD_REQUEST Invalid sort, NOT NULL or CHECK constraint violated, or Error::BadRequest
404 ENTITY_NOT_FOUND No entity has this id (sqlx::Error::RowNotFound, or Error::NotFound)
409 CONFLICT Unique or foreign key constraint violated, or Error::Conflict
500 INTERNAL_ERROR Any other error: its message is logged with the log crate, not sent

Return an octopux::Error from a model, a relation or a BeforeSave hook to answer a client error:

async fn before_save(mut self: Self, _state: &AppState) -> Result<Self> {
    if !self.email.contains('@') {
        return Err(octopux::Error::BadRequest("the email is invalid".into()).into());
    }
    Ok(self)
}

With the openapi feature, every error response is documented with the OctopuxError schema.