From d5f8e70d00af956e4c8f9cc5ce4695fc7ae9f355 Mon Sep 17 00:00:00 2001 From: Peter Todorov Date: Tue, 17 Oct 2023 18:08:43 +0300 Subject: [PATCH] feat: include reqwest::Error in RecaptchaError --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 470ea76..15aef9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,10 +4,10 @@ use std::net::IpAddr; const POST_URL: &str = "https://www.google.com/recaptcha/api/siteverify"; /// Error returned when ReCaptcha verification fails -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug)] pub enum RecaptchaError { Unknown(Option), - HttpError(String), + HttpError(reqwest::Error), MissingInputSecret, InvalidInputSecret, MissingInputResponse, @@ -85,9 +85,9 @@ struct RecaptchaResult { /// let res = recaptcha_verify(recaptcha_secret_key, recaptcha_token, ip).await; /// /// if res.is_ok() { -/// assert_eq!(res, Ok(())); +/// assert!(matches!(res, Ok(()))); /// } else { -/// assert_eq!(res, Err(RecaptchaError::InvalidInputSecret)); +/// assert!(matches!(res, Err(RecaptchaError::InvalidInputSecret))); /// } /// } /// ``` @@ -111,7 +111,7 @@ pub async fn verify( .form(¶ms) .send() .await - .map_err(|e| RecaptchaError::HttpError(e.to_string()))?; + .map_err(RecaptchaError::HttpError)?; if let Ok(result) = response.json::().await { if result.success { @@ -136,6 +136,6 @@ mod tests { async fn it_works() { let res: Result<(), RecaptchaError> = verify("test", "test", None).await; - assert_eq!(res, Err(RecaptchaError::InvalidInputSecret)); + assert!(matches!(res, Err(RecaptchaError::InvalidInputSecret))); } }