Skip to content

Commit d777153

Browse files
committed
Add new Error::SerdePathToError error type
1 parent a0f6d5a commit d777153

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ pub enum Error<T> {
1818
ReqwestMiddleware(reqwest_middleware::Error),
1919
{{/supportMiddleware}}
2020
Serde(serde_json::Error),
21+
{{#useSerdePathToError}}
22+
SerdePathToError(serde_path_to_error::Error<serde_json::Error>),
23+
{{/useSerdePathToError}}
2124
Io(std::io::Error),
2225
ResponseError(ResponseContent<T>),
2326
{{#withAWSV4Signature}}
@@ -38,6 +41,9 @@ impl <T> fmt::Display for Error<T> {
3841
Error::ReqwestMiddleware(e) => ("reqwest-middleware", e.to_string()),
3942
{{/supportMiddleware}}
4043
Error::Serde(e) => ("serde", e.to_string()),
44+
{{#useSerdePathToError}}
45+
Error::SerdePathToError(e) => ("serde", format!("{}: {}", e.path().to_string(), e.inner().to_string())),
46+
{{/useSerdePathToError}}
4147
Error::Io(e) => ("IO", e.to_string()),
4248
Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
4349
{{#withAWSV4Signature}}
@@ -61,6 +67,9 @@ impl <T: fmt::Debug> error::Error for Error<T> {
6167
Error::ReqwestMiddleware(e) => e,
6268
{{/supportMiddleware}}
6369
Error::Serde(e) => e,
70+
{{#useSerdePathToError}}
71+
Error::SerdePathToError(e) => e,
72+
{{/useSerdePathToError}}
6473
Error::Io(e) => e,
6574
Error::ResponseError(_) => return None,
6675
{{#withAWSV4Signature}}
@@ -95,6 +104,14 @@ impl <T> From<serde_json::Error> for Error<T> {
95104
}
96105
}
97106

107+
{{#useSerdePathToError}}
108+
impl<T> From<serde_path_to_error::Error<serde_json::Error>> for Error<T> {
109+
fn from(e: serde_path_to_error::Error<serde_json::Error>) -> Self {
110+
Error::SerdePathToError(e)
111+
}
112+
}
113+
114+
{{/useSerdePathToError}}
98115
impl <T> From<std::io::Error> for Error<T> {
99116
fn from(e: std::io::Error) -> Self {
100117
Error::Io(e)

0 commit comments

Comments
 (0)