Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Error::ResponseError for API errors #25

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

### Bugfixes

- Return `Error::ResponseError` instead of `Error::Transport` for API errors ([#21](https://github.com/Nitrokey/nethsm-sdk-rs/issues/21))

[All Changes](https://github.com/Nitrokey/nethsm-sdk-rs/compare/v1.0.1...HEAD)

## [v1.0.1](https://github.com/Nitrokey/nethsm-sdk-rs/releases/tag/v1.0.1) (2024-05-06)

### Bugfixes
Expand Down
23 changes: 14 additions & 9 deletions generator/src/main/resources/crust/reqwest/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -290,27 +290,27 @@ pub fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allPar
let body_json = body.is_json();
local_var_req_builder = local_var_req_builder.set("content-type", body.content_type());
{{/bodyParams}}{{/hasBodyParam}}
let local_var_resp = if body_json {
local_var_req_builder.send_json(body)?
let local_var_result = if body_json {
local_var_req_builder.send_json(body)
} else {
local_var_req_builder.send_string(body.get_string().as_str())?
local_var_req_builder.send_string(body.get_string().as_str())
};
{{/vendorExtensions.x-consumeMultipleMediaTypes}}
{{^vendorExtensions.x-consumeMultipleMediaTypes}}
{{#consumes}}
local_var_req_builder = local_var_req_builder.set("content-type", "{{{mediaType}}}");
{{#mediaIsJson}}
let local_var_resp = local_var_req_builder.send_json(
let local_var_result = local_var_req_builder.send_json(
{{/mediaIsJson}}
{{^mediaIsJson}}
{{#hasBodyParam}}
{{#bodyParams}}
{{#isFile}}
let {{{paramName}}} = std::io::Cursor::new({{{paramName}}});
let local_var_resp = local_var_req_builder.send(
let local_var_result = local_var_req_builder.send(
{{/isFile}}
{{^isFile}}
let local_var_resp = local_var_req_builder.send_string(
let local_var_result = local_var_req_builder.send_string(
{{/isFile}}
{{/bodyParams}}
{{/hasBodyParam}}
Expand All @@ -323,12 +323,17 @@ pub fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allPar
{{/hasBodyParam}}
{{#consumes}}
{{/consumes}}
{{#hasBodyParam}})?;{{/hasBodyParam}}
{{#hasBodyParam}});{{/hasBodyParam}}
{{/vendorExtensions.x-consumeMultipleMediaTypes}}
{{^hasBodyParam}}
let local_var_resp = local_var_req_builder.call()?;
let local_var_result = local_var_req_builder.call();
{{/hasBodyParam}}

let local_var_resp = local_var_result.or_else(|err| match err {
ureq::Error::Status(_status, resp) => Ok(resp),
_ => Err(err),
})?;


let local_var_headers = super::get_header_map(&local_var_resp);

Expand All @@ -338,7 +343,7 @@ pub fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allPar

let local_var_content_clone = local_var_content.clone();

if !local_var_status >= 400 {
if local_var_status < 400 {
{{#vendorExtensions.x-produceMultipleMediaTypes}}
{{#returnType}}
let local_var_entity : {{{returnType}}} = if is_json { serde_json::from_slice(&local_var_content).map_err(Error::from)? } else { String::from_utf8(local_var_content)? };
Expand Down
Loading
Loading