Skip to content

Commit e8d73f0

Browse files
committed
fix: allow responses for free queries with no allocation open
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 32f30db commit e8d73f0

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

crates/service/src/middleware/attestation.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ pub async fn attestation_middleware(
4545
request: Request,
4646
next: Next,
4747
) -> Result<Response, AttestationError> {
48-
let signer = request
49-
.extensions()
50-
.get::<AttestationSigner>()
51-
.cloned()
52-
.ok_or(AttestationError::CouldNotFindSigner)?;
48+
let signer = request.extensions().get::<AttestationSigner>().cloned();
5349

54-
let (parts, graphql_response) = next.run(request).await.into_parts();
50+
let response = next.run(request).await;
51+
52+
// the only scenario where we don't have a signer is if it's a free query
53+
let (parts, graphql_response) = response.into_parts();
5554
let attestation_response = parts.extensions.get::<AttestationInput>();
5655
let bytes = to_bytes(graphql_response, usize::MAX).await?;
5756
let res = String::from_utf8(bytes.into())?;
5857

59-
let attestation = match attestation_response {
60-
Some(AttestationInput::Attestable { req }) => Some(signer.create_attestation(req, &res)),
58+
let attestation = match (signer, attestation_response) {
59+
(Some(signer), Some(AttestationInput::Attestable { req })) => {
60+
Some(signer.create_attestation(req, &res))
61+
}
6162
_ => None,
6263
};
6364

@@ -73,9 +74,6 @@ pub async fn attestation_middleware(
7374

7475
#[derive(thiserror::Error, Debug)]
7576
pub enum AttestationError {
76-
#[error("Could not find signer for allocation")]
77-
CouldNotFindSigner,
78-
7977
#[error("There was an AxumError: {0}")]
8078
AxumError(#[from] axum::Error),
8179

@@ -89,7 +87,6 @@ pub enum AttestationError {
8987
impl StatusCodeExt for AttestationError {
9088
fn status_code(&self) -> StatusCode {
9189
match self {
92-
AttestationError::CouldNotFindSigner => StatusCode::INTERNAL_SERVER_ERROR,
9390
AttestationError::AxumError(_)
9491
| AttestationError::FromUtf8Error(_)
9592
| AttestationError::SerializationError(_) => StatusCode::BAD_GATEWAY,
@@ -211,6 +208,6 @@ mod tests {
211208
let app = Router::new().route("/", get(handle)).layer(middleware);
212209

213210
let res = send_request(app, None).await;
214-
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
211+
assert_eq!(res.status(), StatusCode::OK);
215212
}
216213
}

0 commit comments

Comments
 (0)