///|
/// Gather, negotiate and encode one complete `/metrics` response.
///
/// This is the main framework-neutral integration entry point.  It never
/// returns a successful response containing a partial exposition: malformed
/// negotiation is 400, unsupported formats are 406, and gather/encoding
/// failures are 500 with a non-sensitive body.
pub fn handle_metrics(
  registry : @registry.Registry,
  accept? : String,
) -> @http.MetricsResponse {
  try @http.negotiate(accept) catch {
    MalformedAccept(_) | AcceptHeaderTooLarge => @http.bad_request_response()
    NotAcceptable => @http.not_acceptable_response()
  } noraise {
    format =>
      try registry.gather() catch {
        _ => @http.internal_error_response()
      } noraise {
        snapshot =>
          try @openmetrics.encode_snapshot(snapshot, format) catch {
            _ => @http.internal_error_response()
          } noraise {
            exposition => @http.metrics_response_from_exposition(exposition)
          }
      }
  }
}