From 3940cb50b34be8e8070054a11ad1350fba6d3e66 Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Tue, 22 Oct 2019 14:42:44 -0500 Subject: [PATCH] feat(publish): better error msg on needs email verif --- src/commands/publish/mod.rs | 39 +++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/commands/publish/mod.rs b/src/commands/publish/mod.rs index 6c36a9920..76e7fdcc5 100644 --- a/src/commands/publish/mod.rs +++ b/src/commands/publish/mod.rs @@ -91,12 +91,11 @@ fn build_and_publish_script( .multipart(script_upload_form) .send()?; - if !res.status().is_success() { - failure::bail!( - "Something went wrong! Status: {}, Details {}", - res.status(), - res.text()? - ) + let res_status = res.status(); + let res_text = res.text()?; + + if !res_status.is_success() { + failure::bail!(error_msg(res_status, res_text)) } let pattern = if target.route.is_some() { @@ -118,6 +117,34 @@ fn build_and_publish_script( Ok(()) } +fn error_msg(status: reqwest::StatusCode, text: String) -> String { + if text.contains("\"code\": 10034,") { + "You need to verify your account's email address before you can publish. You can do this by checking your email or logging in to https://dash.cloudflare.com.".to_string() + } else { + format!("Something went wrong! Status: {}, Details {}", status, text) + } +} + +#[test] +fn fails_with_good_error_msg_on_verify_email_err() { + let text = r#"{ + "result": null, + "success": false, + "errors": [ + { + "code": 10034, + "message": "workers.api.error.email_verification_required" + } + ], + "messages": [] +}"# + .to_string(); + let result = error_msg(text); + assert!( + result.contains("https://dash.cloudflare.com") + ); +} + pub fn upload_buckets( target: &Target, user: &GlobalUser,