Skip to content

Commit

Permalink
Merge pull request #67 from worldcoin/0xkitsune/handle-unexpected-coo…
Browse files Browse the repository at this point in the history
…rdinator-payload

fix(coordinator): handle unexpected payload
  • Loading branch information
0xKitsune authored Feb 29, 2024
2 parents cbc96ef + d9202c2 commit 70fc04b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,26 @@ impl Coordinator {

let body = message.body.context("Missing message body")?;

let UniquenessCheckRequest {
plain_code: template,
if let Ok(UniquenessCheckRequest {
plain_code,
signup_id,
} = serde_json::from_str(&body).context("Failed to parse message")?;
}) = serde_json::from_str::<UniquenessCheckRequest>(&body)
{
self.uniqueness_check(receipt_handle, plain_code, signup_id)
.await?;
} else {
tracing::error!(
?receipt_handle,
"Failed to parse template from message"
);

// Process the query
self.uniqueness_check(receipt_handle, template, signup_id)
sqs_delete_message(
&self.sqs_client,
&self.config.queues.queries_queue_url,
receipt_handle,
)
.await?;
}

Ok(())
}
Expand Down Expand Up @@ -489,6 +501,14 @@ impl Coordinator {
items
} else {
tracing::error!(?receipt_handle, "Failed to parse message body");

sqs_delete_message(
&self.sqs_client,
&self.config.queues.db_sync_queue_url,
receipt_handle,
)
.await?;

return Ok(());
};

Expand Down
8 changes: 8 additions & 0 deletions src/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ impl Participant {
items
} else {
tracing::error!(?receipt_handle, "Failed to parse message body");

sqs_delete_message(
&self.sqs_client,
&self.config.queues.db_sync_queue_url,
receipt_handle,
)
.await?;

return Ok(());
};

Expand Down

0 comments on commit 70fc04b

Please sign in to comment.