[REQ] [cpprestsdk] ApiException is not used in the way it is generated
Created by: CyrilleBenard
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
if (localVarResponse.status_code() >= 400)
{
throw ApiException(localVarResponse.status_code()
, utility::conversions::to_string_t("error calling addPet: ") + localVarResponse.reason_phrase()
, std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
}
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>
class ApiException
: public web::http::http_exception
{
public:
ApiException( int errorCode
, const utility::string_t& message
, std::shared_ptr<std::istream> content = nullptr );
../..
}
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