-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[REQ] [cpprestsdk] ApiException is not used in the way it is generated #3462
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
Comments
@CyrilleBenard In your case please do something like this auto reqTask = api->findPetsByStatus(req)
.then([=](std::vector<std::shared_ptr<Pet>> pets)
{
std::cout << "found pet successfully" << std::endl;
});
try{
reqTask.wait();
}
catch(const ApiException& ex){
std::cout << ex.what() << std::endl << std::flush;
auto ss = std::dynamic_pointer_cast<std::stringstream>( ex.getContent() );
if( nullptr != ss )
{
std::cout << ss->str() << std::endl << std::flush;
}
std::string err(ex.what());
} perform In this case I can see the error like this for example
|
@CyrilleBenard |
@etherealjoy Thanks for your answer and proposal but I did not opened a Bug issue "only" a Feature request :) Throw ApiException using stringstream and catch it using stringstream. No restrictive type inside ApiException class and so, no cast to transform the type in the catch treatment and best performance also. We are also able to write code without a cast and so without any check of nullptr like :
But I still think that it's not as simple as if we only use stringstream. NOTE: greetings EDIT: fix the code alternative I wrote previously |
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
The generator produces code that uses ApiException not in the way it has been intended. Ok, this is not exactly true but let me show what I mean thanks to the PetApi example :
In the file PetApi.cpp line 136 we can see one error treatment throwing an ApiException
The 3rd parameter of the ApiException is set with a std::make_shared<std::stringstream> whereas the ApiException shows the corresponding API with a std::shared_ptr<std::istream>
Of course this is allowed because a std::stringstream IS A std::istream but when I (the developer) want to handle an ApiException in my application, I retrieve "'only" an std::istream that is not really convenient to use whereas at the origin, the ApiException has been raised with a std::stringstream.
Describe the solution you'd like
What about modifying the ApiException and replace the use of std::istream with std::stringstream ?
Describe alternatives you've considered
N/A
Additional context
N/A
The text was updated successfully, but these errors were encountered: