Http/throw on read error (#274)
* throw exception on Read from wire Error instead of returning -1 * throw exception if read from socket is not CURLE_OK * missing header for Win * fix header on windows * Add more description to transport errors
This commit is contained in:
parent
3db59439c9
commit
12b389a579
@ -11,6 +11,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Azure { namespace Core { namespace Http {
|
||||
|
||||
@ -263,20 +264,15 @@ namespace Azure { namespace Core { namespace Http {
|
||||
/*
|
||||
* Response exceptions
|
||||
*/
|
||||
struct CouldNotResolveHostException : public std::exception
|
||||
struct CouldNotResolveHostException : public std::runtime_error
|
||||
{
|
||||
const char* what() const throw() { return "could not resolve host"; }
|
||||
};
|
||||
|
||||
struct ErrorWhileWrittingResponse : public std::exception
|
||||
{
|
||||
const char* what() const throw() { return "could not write response"; }
|
||||
explicit CouldNotResolveHostException(std::string const& msg) : std::runtime_error(msg) {}
|
||||
};
|
||||
|
||||
// Any other excpetion from transport layer without an specific exception defined above
|
||||
struct TransportException : public std::exception
|
||||
struct TransportException : public std::runtime_error
|
||||
{
|
||||
const char* what() const throw() { return "Error on transport layer while sending request"; }
|
||||
explicit TransportException(std::string const& msg) : std::runtime_error(msg) {}
|
||||
};
|
||||
|
||||
class Response {
|
||||
|
||||
@ -21,15 +21,13 @@ std::unique_ptr<Response> CurlTransport::Send(Context& context, Request& request
|
||||
{
|
||||
case CURLE_COULDNT_RESOLVE_HOST:
|
||||
{
|
||||
throw Azure::Core::Http::CouldNotResolveHostException();
|
||||
}
|
||||
case CURLE_WRITE_ERROR:
|
||||
{
|
||||
throw Azure::Core::Http::ErrorWhileWrittingResponse();
|
||||
throw new Azure::Core::Http::CouldNotResolveHostException(
|
||||
"Could not resolve host " + request.GetHost());
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw Azure::Core::Http::TransportException();
|
||||
throw new Azure::Core::Http::TransportException(
|
||||
"Error while sending request. " + std::string(curl_easy_strerror(performing)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -526,14 +524,15 @@ int64_t CurlSession::ReadSocketToBuffer(uint8_t* buffer, int64_t bufferSize)
|
||||
if (!WaitForSocketReady(this->m_curlSocket, 0, 60000L))
|
||||
{
|
||||
// TODO: Change this to somehing more relevant
|
||||
throw;
|
||||
throw new Azure::Core::Http::TransportException(
|
||||
"Timeout waiting to read from Network socket");
|
||||
}
|
||||
break;
|
||||
case CURLE_OK:
|
||||
break;
|
||||
default:
|
||||
// Error code while reading from socket
|
||||
throw Azure::Core::Http::TransportException();
|
||||
throw new Azure::Core::Http::TransportException("Error while reading from network socket");
|
||||
}
|
||||
}
|
||||
return readBytes;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user