Skip to content

Commit

Permalink
better uniqueness handling
Browse files Browse the repository at this point in the history
  • Loading branch information
m1guelpf committed Dec 13, 2023
1 parent d3cc90c commit 50ebcf8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async fn verify_page(
}})
if (res.ok) alert('Successfully verified! You can now close this and go back to the group.')
else if (res.status === 429) alert('This World ID has already been used to join this group. You can\'t do it again!')
else alert('Something went wrong, please try again later.')
window.close()
Expand Down Expand Up @@ -136,11 +137,23 @@ async fn verify_api(
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;

if req.status().is_client_error() || req.status().is_server_error() {
log::error!(
"Developer Portal returned error: {:?}",
req.json::<serde_json::Value>().await,
);
let res = req.json::<serde_json::Value>().await.map_err(|e| {
log::error!("Failed to deserialize dev portal body: {e:?}");

StatusCode::INTERNAL_SERVER_ERROR
})?;

let Some(code) = res.get("code") else {
log::error!("Developer Portal returned error: {:?}", res);

return Err(StatusCode::BAD_REQUEST);
};

if code.as_str() == Some("max_verifications_reached") {
return Err(StatusCode::TOO_MANY_REQUESTS);
}

log::error!("Failed to verify proof: {:?}", res);
return Err(StatusCode::BAD_REQUEST);
}

Expand Down

0 comments on commit 50ebcf8

Please sign in to comment.