Skip to main content

service_error_response

Function service_error_response 

Source
pub fn service_error_response<T>(
    err: &ServiceError,
) -> (StatusCode, Json<ApiResponse<T>>)
Expand description

The response for a failed ServiceError, for handlers outside the generic CRUD handler (a generated state-machine transition, a custom route) that call the service directly.

A refusal for named reasons — a protected field, a broken rule, a constraint the database refused — is the caller’s to fix, so it answers 422 with the violations listed, exactly as the generic handler does; it must never surface as a 500. A plain validation error answers 400, a missing record 404, a duplicate or conflict 409, and only what is left is a 500.