question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[REQ][Rust Client] New Success types lead to exessive code when using the API

See original GitHub issue

Is your feature request related to a problem? Please describe.

Before #6481 has been merged this morning, my test code for using the 5.0.0 SNAPSHOT with supportAsync: true and useSingleRequestParameter: true looked something like this:

    let servers = servers_api::list_servers(&configuration, params)
        .await
        .map_err(|err| format!("API call to list_servers failed: {:?}", err))?
        .servers;

For the same behaviour, I now have to write:

    let success = servers_api::list_servers(&configuration, params)
        .await
        .map_err(|err| format!("API call to list_servers failed: {:?}", err))?
        .entity
        .ok_or("API call to list_servers failed: Response could not be parsed.".to_string())?;
    let servers = match success {
        servers_api::ListServersSuccess::Status200(response) => Ok(response.servers),
        _ => Err("API call to list_servers failed: Unexpected success status code.".to_string()),
    }?;

In my oppinion, the code has become unnecessarily complex here.

Describe the solution you’d like

I am not sure if I overlooked a way for a simpler approach, but it would be nice to only deal with one layer of error handling when using the API.

Describe alternatives you’ve considered

As this is only related to template code, I can of course change this back to the previous behaviour using a customized templates, but I would like to stick to the default templates as far as possible.

Additional context

I am now using SNAPSHOT version 5.0.0-20200613.071037-272.

Thanks for looking into this! If I can give a hand finding a solution, I would be glad to do so.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
bcourtinecommented, Jun 17, 2020

Good idea: just renamed the param to supportMultipleResponses.

1reaction
bcourtinecommented, Jun 15, 2020

Hi @HenningHolmDE ,

I am the culprit for this PR, but I agree. In the first place, I did not want to implement it because code is now more complex, but it was a feature request to handle multiple 2xx schemas (which is very rare).

After discussion with @wing328 we will propose the feature as optionnal, adding a CLI option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Write A REST Client In Rust | A learning journal
The main type you will be dealing with when working with reqwest is reqwest::Client - it exposes all the methods we need to...
Read more >
Making HTTP requests in Rust with Reqwest - LogRocket Blog
The Rust Reqwest library is built for fetching resources using the HTTP protocol. This guide explains how to get started with it.
Read more >
Best practices for API error handling and troubleshooting
Orange APIs use appropriate HTTP response status codes to indicate whether a specific HTTP request has been successfully completed or not.
Read more >
How a RESTful API server reacts to requests - O'Reilly
Learn how to properly design RESTful APIs communication with clients, accounting for request structure, authentication, and caching.
Read more >
Web API implementation - Best practices for cloud applications
Learn about best practices for implementing a web API and publishing it to make it available to client applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found