14 , _errorMessage(
std::move(msg) )
15 , _extraInfo(
std::move(extraInfo) )
34 std::map<std::string, boost::any> extraInfo;
36 if ( nativeCode != 0 ) {
38 const char *nativeErr = curl_easy_strerror( static_cast<CURLcode>(nativeCode) );
39 if ( nativeErr !=
nullptr )
40 extraInfo.insert( {
"nativeErrorCodeDesc", std::string( nativeErr ) } );
42 if ( errBuf !=
nullptr )
43 extraInfo.insert( {
"nativeErrorDesc", std::string( errBuf ) } );
45 extraInfo.insert( {
"requestUrl",
url } );
46 extraInfo.insert( {
"curlCode", nativeCode } );
52 case CURLE_UNSUPPORTED_PROTOCOL:
57 err +=
" or redirect (";
62 case CURLE_URL_MALFORMAT:
case CURLE_URL_MALFORMAT_USER:
65 case CURLE_LOGIN_DENIED:
68 case CURLE_HTTP_RETURNED_ERROR: {
69 long httpReturnCode = 0;
70 CURLcode infoRet = curl_easy_getinfo( req.
nativeHandle(),
71 CURLINFO_RESPONSE_CODE,
74 if ( infoRet == CURLE_OK ) {
75 extraInfo.insert( {
"responseCode", httpReturnCode } );
78 switch ( httpReturnCode )
81 std::string auth_hint;
83 long auth_info = CURLAUTH_NONE;
86 curl_easy_getinfo(req.
nativeHandle(), CURLINFO_HTTPAUTH_AVAIL, &auth_info);
88 if(infoRet == CURLE_OK) {
107 err =
zypp::str::form(
_(
"Location '%s' is temporarily unaccessible."),
url.asString().c_str() );
111 err =
zypp::str::form(
_(
"Timeout exceeded when accessing '%s'."),
url.asString().c_str() );
115 if (
url.getHost().find(
".suse.com") != std::string::npos )
116 msg403 =
_(
"Visit the SUSE Customer Center to check whether your registration is valid and has not expired.");
117 else if (
url.asString().find(
"novell.com") != std::string::npos)
118 msg403 =
_(
"Visit the Novell Customer Center to check whether your registration is valid and has not expired.");
139 "Unable to retrieve HTTP response\n"),
url.asString().c_str() ) ;
143 case CURLE_FTP_COULDNT_RETR_FILE:
144 #if CURLVERSION_AT_LEAST(7,16,0) 145 case CURLE_REMOTE_FILE_NOT_FOUND:
147 case CURLE_FTP_ACCESS_DENIED:
148 case CURLE_TFTP_NOTFOUND:
151 case CURLE_BAD_PASSWORD_ENTERED:
152 case CURLE_FTP_USER_PASSWORD_INCORRECT:
155 case CURLE_COULDNT_RESOLVE_PROXY:
156 case CURLE_COULDNT_RESOLVE_HOST:
157 case CURLE_COULDNT_CONNECT:
158 case CURLE_FTP_CANT_GET_HOST:
161 case CURLE_WRITE_ERROR:
164 case CURLE_PARTIAL_FILE:
165 case CURLE_OPERATION_TIMEDOUT:
168 case CURLE_ABORTED_BY_CALLBACK:
171 case CURLE_PEER_FAILED_VERIFICATION:
189 const char *nativeErr = curl_multi_strerror( static_cast<CURLMcode>(nativeCode) );
191 std::map<std::string, boost::any> extraInfo;
192 extraInfo.insert( {
"curlMCode", nativeCode } );
195 if ( nativeErr ==
nullptr )
196 err =
"The dispatcher returned an unknown error";
198 err = std::string( nativeErr );
214 return d_func()->_errorCode;
219 return d_func()->_errorMessage;
224 return d_func()->_errorCode !=
NoError;
229 return d_func()->_extraInfo;
238 return "Internal Error";
240 return "The request was cancelled";
242 return "The request exceeded the maximum download size";
244 return "The downloaded data did not result in a valid checksum";
246 return "The peer certificate could not be verified";
248 return "Connection failed";
250 return "Unsupported protocol";
254 return "Requested location is temporarily unaccessible.";
256 return "Timeout reached";
258 return "Access to requested URL is forbidden.";
260 return "File not found";
262 return "Authentication required but not provided.";
264 return "Login failed.";
266 return "Server returned an error for the given request.";
268 return std::string();
275 auto it = d->_extraInfo.find(
"nativeErrorDesc");
276 if ( it != d->_extraInfo.end() ) {
278 return boost::any_cast<std::string>( it->second );
279 }
catch (
const boost::bad_any_cast &) { }
282 it = d->_extraInfo.find(
"nativeErrorCodeDesc");
283 if ( it != d->_extraInfo.end() ) {
285 return boost::any_cast<std::string>( it->second );
286 }
catch (
const boost::bad_any_cast &) { }
289 return std::string();
bool isError() const
isError Will return true if this is a actual error
void * nativeHandle() const
const std::string & lastRedirectInfo() const
static zyppng::NetworkRequestError fromCurlMError(int nativeCode)
const char * c_str() const
String representation.
std::string toString() const
toString Returns a string representation of the error
std::string nativeErrorString() const
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
TransferSettings & transferSettings()
static std::string typeToString(NetworkRequestError::Type t)
const std::map< std::string, boost::any > & extraInfo() const
const std::string & asString() const
String representation.
NetworkRequestErrorPrivate(NetworkRequestError::Type code, std::string &&msg, std::map< std::string, boost::any > &&extraInfo)
The NetworkRequestError class Represents a error that occured in.
std::string numstring(char n, int w=0)
const zypp::Pathname & targetFilePath() const
Returns the target filename path.
static zyppng::NetworkRequestError fromCurlError(NetworkRequest &req, int nativeCode, const char *errBuf)
Type type() const
type Returns the type of the error
ZYPP_IMPL_PRIVATE(NetworkRequestError)
NetworkRequestErrorPrivate * clone() const
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})