From 50ebcf8972a9117741aad5bef369e2dab936e442 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Wed, 13 Dec 2023 14:01:01 +0100 Subject: [PATCH] better uniqueness handling --- src/server/mod.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index 6730329..06286e8 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -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() @@ -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::().await, - ); + let res = req.json::().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); }