to_handler_error

Function to_handler_error 

Source
pub fn to_handler_error(e: Error) -> (StatusCode, Json<ErrorResponse>)
Expand description

Convert a [BackendError] (from the service layer) into the best-fitting (StatusCode, Json<ErrorResponse>) pair returned by every handler. The canonical call shape is .map_err(to_handler_error)? at the end of each service call.

Status mapping (most-specific first):

  • NotFound, SessionNotFound, ConfigurationNotFound → 404
  • Conflict, ConfigurationAlreadyExistsError → 409
  • BadRequest, InvalidPattern, UnsupportedBackend, InvalidNodeId → 400
  • AuthenticationTokenNotFound, JwtMalformed → 401
  • InsufficientResources → 422
  • CsmError { status, .. } → that backend status (verbatim) when it’s a valid HTTP code, else 502 Bad Gateway
  • NetError(rqe) where rqe.is_timeout() → 504 Gateway Timeout (manta-server → CSM hop)
  • everything else → 500 Internal Server Error

pub (rather than pub(crate)) so the integration tests in crates/manta-server/tests/ can exercise the mapping directly.