From c2454cd50768a0e9230d7ff93b12424d34f36075 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Thu, 19 Oct 2023 23:05:42 -0700 Subject: [PATCH] updates Signed-off-by: Jess Frazelle --- Cargo.lock | 2 +- VERSION.txt | 2 +- kittycad.rs.patch.json | 2 +- kittycad/Cargo.toml | 2 +- kittycad/README.md | 2 +- kittycad/src/ai.rs | 30 +++++++++++--- kittycad/src/api_calls.rs | 72 ++++++++++++++++++++++++++------ kittycad/src/api_tokens.rs | 30 +++++++++++--- kittycad/src/apps.rs | 18 ++++++-- kittycad/src/executor.rs | 6 ++- kittycad/src/file.rs | 36 +++++++++++++--- kittycad/src/hidden.rs | 18 ++++++-- kittycad/src/lib.rs | 2 +- kittycad/src/meta.rs | 36 +++++++++++++--- kittycad/src/oauth2.rs | 36 +++++++++++++--- kittycad/src/payments.rs | 60 ++++++++++++++++++++++----- kittycad/src/types.rs | 11 +++++ kittycad/src/unit.rs | 78 +++++++++++++++++++++++++++++------ kittycad/src/users.rs | 78 +++++++++++++++++++++++++++++------ openapitor/src/functions.rs | 4 +- openapitor/src/types/error.rs | 12 ++++++ 21 files changed, 447 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c274d185..ece2fcc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -961,7 +961,7 @@ dependencies = [ [[package]] name = "kittycad" -version = "0.2.36" +version = "0.2.37" dependencies = [ "anyhow", "async-trait", diff --git a/VERSION.txt b/VERSION.txt index d4ca806c..aa049997 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.2.36 +0.2.37 diff --git a/kittycad.rs.patch.json b/kittycad.rs.patch.json index 15585ee3..073f9e87 100644 --- a/kittycad.rs.patch.json +++ b/kittycad.rs.patch.json @@ -4,7 +4,7 @@ "path": "/info/x-rust", "value": { "client": "// Authenticate via an API token.\nlet client = kittycad::Client::new(\"$TOKEN\");\n\n// - OR -\n\n// Authenticate with your token and host parsed from the environment variables:\n// `KITTYCAD_API_TOKEN`.\nlet client = kittycad::Client::new_from_env();", - "install": "[dependencies]\nkittycad = \"0.2.36\"" + "install": "[dependencies]\nkittycad = \"0.2.37\"" } }, { diff --git a/kittycad/Cargo.toml b/kittycad/Cargo.toml index eb013bb8..704fbd25 100644 --- a/kittycad/Cargo.toml +++ b/kittycad/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kittycad" description = "A fully generated & opinionated API client for the KittyCAD API." -version = "0.2.36" +version = "0.2.37" documentation = "https://docs.rs/kittycad" readme = "README.md" repository = "https://github.com/KittyCAD/kittycad.rs/tree/main/kittycad" diff --git a/kittycad/README.md b/kittycad/README.md index 09080a6d..f7b0d901 100644 --- a/kittycad/README.md +++ b/kittycad/README.md @@ -31,7 +31,7 @@ To install the library, add the following to your `Cargo.toml` file. ```toml [dependencies] -kittycad = "0.2.36" +kittycad = "0.2.37" ``` ## Basic example diff --git a/kittycad/src/ai.rs b/kittycad/src/ai.rs index 872cdb3e..520be7d5 100644 --- a/kittycad/src/ai.rs +++ b/kittycad/src/ai.rs @@ -41,7 +41,11 @@ impl Ai { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -88,7 +92,11 @@ impl Ai { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -134,7 +142,11 @@ impl Ai { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }) } } .map_ok(|result: crate::types::TextToCadResultsPage| { @@ -190,7 +202,11 @@ impl Ai { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -227,7 +243,11 @@ impl Ai { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/api_calls.rs b/kittycad/src/api_calls.rs index aa33673a..88cffaaf 100644 --- a/kittycad/src/api_calls.rs +++ b/kittycad/src/api_calls.rs @@ -36,7 +36,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -78,7 +82,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -124,7 +132,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }) } } .map_ok(|result: crate::types::ApiCallWithPriceResultsPage| { @@ -171,7 +183,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -218,7 +234,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -264,7 +284,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }) } } .map_ok(|result: crate::types::AsyncApiCallResultsPage| { @@ -321,7 +345,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -363,7 +391,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -409,7 +441,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }) } } .map_ok(|result: crate::types::ApiCallWithPriceResultsPage| { @@ -463,7 +499,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -510,7 +550,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -561,7 +605,11 @@ impl ApiCalls { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }) } } .map_ok(|result: crate::types::ApiCallWithPriceResultsPage| { diff --git a/kittycad/src/api_tokens.rs b/kittycad/src/api_tokens.rs index 70271ee4..ef24cd85 100644 --- a/kittycad/src/api_tokens.rs +++ b/kittycad/src/api_tokens.rs @@ -50,7 +50,11 @@ impl ApiTokens { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -95,7 +99,11 @@ impl ApiTokens { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }) } } .map_ok(|result: crate::types::ApiTokenResultsPage| { @@ -137,7 +145,11 @@ impl ApiTokens { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -167,7 +179,11 @@ impl ApiTokens { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -201,7 +217,11 @@ impl ApiTokens { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/apps.rs b/kittycad/src/apps.rs index c2048ab7..1c042afe 100644 --- a/kittycad/src/apps.rs +++ b/kittycad/src/apps.rs @@ -36,7 +36,11 @@ impl Apps { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -68,7 +72,11 @@ impl Apps { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -89,7 +97,11 @@ impl Apps { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/executor.rs b/kittycad/src/executor.rs index 8c836c2a..be0cb926 100644 --- a/kittycad/src/executor.rs +++ b/kittycad/src/executor.rs @@ -58,7 +58,11 @@ impl Executor { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } diff --git a/kittycad/src/file.rs b/kittycad/src/file.rs index 51e38588..593bb71a 100644 --- a/kittycad/src/file.rs +++ b/kittycad/src/file.rs @@ -43,7 +43,11 @@ impl File { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -95,7 +99,11 @@ impl File { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -161,7 +169,11 @@ impl File { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -205,7 +217,11 @@ impl File { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -257,7 +273,11 @@ impl File { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -309,7 +329,11 @@ impl File { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/hidden.rs b/kittycad/src/hidden.rs index 04b689ce..e89407ce 100644 --- a/kittycad/src/hidden.rs +++ b/kittycad/src/hidden.rs @@ -35,7 +35,11 @@ impl Hidden { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -66,7 +70,11 @@ impl Hidden { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -86,7 +94,11 @@ impl Hidden { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/lib.rs b/kittycad/src/lib.rs index 429ba3b2..c436ecaf 100644 --- a/kittycad/src/lib.rs +++ b/kittycad/src/lib.rs @@ -29,7 +29,7 @@ //! //! ```toml //! [dependencies] -//! kittycad = "0.2.36" +//! kittycad = "0.2.37" //! ``` //! //! ## Basic example diff --git a/kittycad/src/meta.rs b/kittycad/src/meta.rs index e2625c2e..86457d4d 100644 --- a/kittycad/src/meta.rs +++ b/kittycad/src/meta.rs @@ -34,7 +34,11 @@ impl Meta { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -59,7 +63,11 @@ impl Meta { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -90,7 +98,11 @@ impl Meta { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -129,7 +141,11 @@ impl Meta { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -159,7 +175,11 @@ impl Meta { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -185,7 +205,11 @@ impl Meta { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/oauth2.rs b/kittycad/src/oauth2.rs index a91eb985..d6e983d0 100644 --- a/kittycad/src/oauth2.rs +++ b/kittycad/src/oauth2.rs @@ -37,7 +37,11 @@ impl Oauth2 { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -66,7 +70,11 @@ impl Oauth2 { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -87,7 +95,11 @@ impl Oauth2 { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -116,7 +128,11 @@ impl Oauth2 { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -162,7 +178,11 @@ impl Oauth2 { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -209,7 +229,11 @@ impl Oauth2 { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/payments.rs b/kittycad/src/payments.rs index f13a9fc7..081a47ec 100644 --- a/kittycad/src/payments.rs +++ b/kittycad/src/payments.rs @@ -39,7 +39,11 @@ impl Payments { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -83,7 +87,11 @@ impl Payments { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -127,7 +135,11 @@ impl Payments { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -151,7 +163,11 @@ impl Payments { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -176,7 +192,11 @@ impl Payments { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -201,7 +221,11 @@ impl Payments { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -226,7 +250,11 @@ impl Payments { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -251,7 +279,11 @@ impl Payments { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -275,7 +307,11 @@ impl Payments { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -301,7 +337,11 @@ impl Payments { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/types.rs b/kittycad/src/types.rs index 1b4bf459..b21b06d1 100644 --- a/kittycad/src/types.rs +++ b/kittycad/src/types.rs @@ -329,6 +329,13 @@ pub mod error { #[doc = " The full response."] response: reqwest::Response, }, + #[doc = " An error from the server."] + Server { + #[doc = " The text from the body."] + body: String, + #[doc = " The response status."] + status: reqwest::StatusCode, + }, #[doc = " A response not listed in the API description. This may represent a"] #[doc = " success or failure response; check `status().is_success()`."] UnexpectedResponse(reqwest::Response), @@ -346,6 +353,7 @@ pub mod error { Error::CommunicationError(reqwest_middleware::Error::Middleware(_)) => None, Error::SerdeError { error: _, status } => Some(*status), Error::InvalidResponsePayload { error: _, response } => Some(response.status()), + Error::Server { body: _, status } => Some(*status), Error::UnexpectedResponse(r) => Some(r.status()), } } @@ -391,6 +399,9 @@ pub mod error { Error::InvalidResponsePayload { error, response: _ } => { write!(f, "Invalid Response Payload: {}", error) } + Error::Server { body, status } => { + write!(f, "Server Error: {} {}", status, body) + } Error::UnexpectedResponse(r) => { write!(f, "Unexpected Response: {:?}", r) } diff --git a/kittycad/src/unit.rs b/kittycad/src/unit.rs index 93069b52..8a3662da 100644 --- a/kittycad/src/unit.rs +++ b/kittycad/src/unit.rs @@ -54,7 +54,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -100,7 +104,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -136,7 +144,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -172,7 +184,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -218,7 +234,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -254,7 +274,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -300,7 +324,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -346,7 +374,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -392,7 +424,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -428,7 +464,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -464,7 +504,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -500,7 +544,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -546,7 +594,11 @@ impl Unit { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/kittycad/src/users.rs b/kittycad/src/users.rs index 1deee978..f6cb74cc 100644 --- a/kittycad/src/users.rs +++ b/kittycad/src/users.rs @@ -36,7 +36,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -63,7 +67,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -85,7 +93,11 @@ impl Users { if status.is_success() { Ok(()) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -110,7 +122,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -138,7 +154,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -168,7 +188,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -206,7 +230,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -248,7 +276,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -292,7 +324,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }) } } .map_ok(|result: crate::types::UserResultsPage| { @@ -351,7 +387,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -396,7 +436,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }) } } .map_ok(|result: crate::types::ExtendedUserResultsPage| { @@ -452,7 +496,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } @@ -482,7 +530,11 @@ impl Users { ) }) } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server { + body: text.to_string(), + status, + }); } } } diff --git a/openapitor/src/functions.rs b/openapitor/src/functions.rs index 3ad4014d..bef1cb96 100644 --- a/openapitor/src/functions.rs +++ b/openapitor/src/functions.rs @@ -1261,7 +1261,9 @@ fn get_function_body( if status.is_success() { #response } else { - Err(crate::types::error::Error::UnexpectedResponse(resp)) + // Try to decode the error. + let text = resp.text().await.unwrap_or_default(); + return Err(crate::types::error::Error::Server{body:text.to_string(), status}); } }) } diff --git a/openapitor/src/types/error.rs b/openapitor/src/types/error.rs index c74ed07c..5997deb3 100644 --- a/openapitor/src/types/error.rs +++ b/openapitor/src/types/error.rs @@ -32,6 +32,14 @@ pub enum Error { response: reqwest::Response, }, + /// An error from the server. + Server { + /// The text from the body. + body: String, + /// The response status. + status: reqwest::StatusCode, + }, + /// A response not listed in the API description. This may represent a /// success or failure response; check `status().is_success()`. UnexpectedResponse(reqwest::Response), @@ -49,6 +57,7 @@ impl Error { Error::CommunicationError(reqwest_middleware::Error::Middleware(_)) => None, Error::SerdeError { error: _, status } => Some(*status), Error::InvalidResponsePayload { error: _, response } => Some(response.status()), + Error::Server { body: _, status } => Some(*status), Error::UnexpectedResponse(r) => Some(r.status()), } } @@ -94,6 +103,9 @@ impl std::fmt::Display for Error { Error::InvalidResponsePayload { error, response: _ } => { write!(f, "Invalid Response Payload: {}", error) } + Error::Server { body, status } => { + write!(f, "Server Error: {} {}", status, body) + } Error::UnexpectedResponse(r) => { write!(f, "Unexpected Response: {:?}", r) }