| 187 | } |
| 188 | |
| 189 | fn with_request_id(status: Status, request_id: &str) -> Status { |
| 190 | let code = match status.code() { |
| 191 | tonic::Code::Unavailable => ErrorCode::ResourceExhausted, |
| 192 | tonic::Code::InvalidArgument => ErrorCode::InvalidArgument, |
| 193 | tonic::Code::NotFound => ErrorCode::RepositoryNotFound, |
| 194 | tonic::Code::FailedPrecondition => ErrorCode::PreconditionFailed, |
| 195 | _ => ErrorCode::Internal, |
| 196 | }; |
| 197 | let info = ErrorInfo { |
| 198 | code: code as i32, |
| 199 | message: status.message().to_string(), |
| 200 | request_id: Some(request_id.to_string()), |
| 201 | ..Default::default() |
| 202 | }; |
| 203 | Status::with_details(status.code(), status.message(), info.encode_to_vec().into()) |
| 204 | } |
| 205 | |
| 206 | #[cfg(test)] |
| 207 | mod tests; |