This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pretty-print api errors (#593)
Fixes RVT-4139
- Loading branch information
1 parent
d7a6508
commit 66fd193
Showing
7 changed files
with
84 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
diff --git a/sdks/rust/src/apis/mod.rs b/sdks/rust/src/apis/mod.rs | ||
index 73ed6261..caa52f60 100644 | ||
--- a/sdks/rust/src/apis/mod.rs | ||
+++ b/sdks/rust/src/apis/mod.rs | ||
@@ -16,16 +16,33 @@ pub enum Error<T> { | ||
ResponseError(ResponseContent<T>), | ||
} | ||
|
||
+#[derive(serde::Deserialize)] | ||
+pub struct RivetErrorBody { | ||
+ pub code: String, | ||
+ pub message: String, | ||
+ pub documentation: Option<String>, | ||
+} | ||
+ | ||
impl<T> fmt::Display for Error<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let (module, e) = match self { | ||
Error::Reqwest(e) => ("reqwest", e.to_string()), | ||
Error::Serde(e) => ("serde", e.to_string()), | ||
Error::Io(e) => ("IO", e.to_string()), | ||
- Error::ResponseError(e) => ( | ||
- "response", | ||
- format!("status code {}\n{}", e.status, e.content), | ||
- ), | ||
+ Error::ResponseError(e) => { | ||
+ if let Ok(body) = serde_json::from_str::<RivetErrorBody>(&e.content) { | ||
+ write!(f, "{}", body.message)?; | ||
+ if let Some(docs) = &body.documentation { | ||
+ write!(f, "\n{docs}")?; | ||
+ } | ||
+ return Ok(()); | ||
+ } | ||
+ | ||
+ ( | ||
+ "response", | ||
+ format!("status code {}\n{}", e.status, e.content), | ||
+ ) | ||
+ } | ||
}; | ||
write!(f, "error in {}: {}", module, e) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.