relay_server/endpoints/
events.rs

1//! Returns captured events.
2
3use axum::extract::Path;
4use axum::http::{StatusCode, header};
5use axum::response::IntoResponse;
6use relay_event_schema::protocol::EventId;
7
8use crate::endpoints::common::ServiceUnavailable;
9use crate::envelope;
10use crate::service::ServiceState;
11use crate::services::test_store::GetCapturedEnvelope;
12
13pub async fn handle(
14    state: ServiceState,
15    Path(event_id): Path<EventId>,
16) -> Result<impl IntoResponse, ServiceUnavailable> {
17    let envelope_opt = state
18        .test_store()
19        .send(GetCapturedEnvelope { event_id })
20        .await?;
21
22    Ok(match envelope_opt {
23        Some(Ok(envelope)) => {
24            let headers = [(header::CONTENT_TYPE, envelope::CONTENT_TYPE)];
25            (StatusCode::OK, headers, envelope.to_vec().unwrap()).into_response()
26        }
27        Some(Err(error)) => (StatusCode::BAD_REQUEST, error).into_response(),
28        None => StatusCode::NOT_FOUND.into_response(),
29    })
30}