12#include <zypp/base/Gettext.h>
13#include <zypp-curl/auth/CurlAuthData>
25 , _errorMessage(
std::move(msg) )
26, _extraInfo(
std::move(extraInfo) )
45 std::map<std::string, boost::any> extraInfo;
47 if ( nativeCode != 0 ) {
49 const char *nativeErr = curl_easy_strerror(
static_cast<CURLcode
>(nativeCode) );
50 if ( nativeErr !=
nullptr )
53 if ( !nativeError.empty() )
56 extraInfo.insert( {
"requestUrl", url } );
57 extraInfo.insert( {
"curlCode", nativeCode } );
58 extraInfo.insert( {
"filepath", req.
targetFilePath().asString() } );
63 case CURLE_UNSUPPORTED_PROTOCOL:
68 err +=
" or redirect (";
73 case CURLE_URL_MALFORMAT:
case CURLE_URL_MALFORMAT_USER:
76 case CURLE_LOGIN_DENIED:
79 case CURLE_HTTP_RETURNED_ERROR: {
80 long httpReturnCode = 0;
81 CURLcode infoRet = curl_easy_getinfo( req.
nativeHandle(),
82 CURLINFO_RESPONSE_CODE,
85 if ( infoRet == CURLE_OK ) {
86 extraInfo.insert( {
"responseCode", httpReturnCode } );
89 switch ( httpReturnCode )
92 std::string auth_hint;
94 long auth_info = CURLAUTH_NONE;
97 curl_easy_getinfo(req.
nativeHandle(), CURLINFO_HTTPAUTH_AVAIL, &auth_info);
99 if(infoRet == CURLE_OK) {
118 err =
zypp::str::form(
_(
"Location '%s' is temporarily unaccessible."), url.asString().c_str() );
122 err =
zypp::str::form(
_(
"Timeout exceeded when accessing '%s'."), url.asString().c_str() );
126 if ( url.getHost().find(
".suse.com") != std::string::npos )
127 msg403 =
_(
"Visit the SUSE Customer Center to check whether your registration is valid and has not expired.");
128 else if (url.asString().find(
"novell.com") != std::string::npos)
129 msg403 =
_(
"Visit the Novell Customer Center to check whether your registration is valid and has not expired.");
150 "Unable to retrieve HTTP response\n"), url.asString().c_str() ) ;
154 case CURLE_FTP_COULDNT_RETR_FILE:
155#if CURLVERSION_AT_LEAST(7,16,0)
156 case CURLE_REMOTE_FILE_NOT_FOUND:
158 case CURLE_FTP_ACCESS_DENIED:
159 case CURLE_TFTP_NOTFOUND:
162 case CURLE_BAD_PASSWORD_ENTERED:
163 case CURLE_FTP_USER_PASSWORD_INCORRECT:
166 case CURLE_COULDNT_RESOLVE_PROXY:
167 case CURLE_COULDNT_RESOLVE_HOST:
168 case CURLE_COULDNT_CONNECT:
169 case CURLE_FTP_CANT_GET_HOST:
172 case CURLE_WRITE_ERROR: {
177 case CURLE_PARTIAL_FILE:
180 case CURLE_OPERATION_TIMEDOUT:
183 case CURLE_ABORTED_BY_CALLBACK:
186 case CURLE_PEER_FAILED_VERIFICATION:
192 case CURLE_HTTP2_STREAM:
211 const char *nativeErr = curl_multi_strerror(
static_cast<CURLMcode
>(nativeCode) );
213 std::map<std::string, boost::any> extraInfo;
214 extraInfo.insert( {
"curlMCode", nativeCode } );
217 if ( nativeErr ==
nullptr )
218 err =
"The dispatcher returned an unknown error";
220 err = std::string( nativeErr );
235 return d_func()->_errorCode;
240 return d_func()->_errorMessage;
245 return d_func()->_errorCode !=
NoError;
250 return d_func()->_extraInfo;
259 return "Internal Error";
261 return "The request was cancelled";
263 return "The request exceeded the maximum download size";
265 return "The downloaded data did not result in a valid checksum";
267 return "The peer certificate could not be verified";
269 return "Connection failed";
271 return "Unsupported protocol";
275 return "Requested location is temporarily unaccessible.";
277 return "Timeout reached";
279 return "Access to requested URL is forbidden.";
281 return "File not found";
283 return "Authentication required but not provided.";
285 return "Login failed.";
287 return "Server returned an error for the given request.";
289 return "Server did not send all requested ranges.";
291 return "Invalid data from server, multipart was requested but there was no range status code.";
293 return "Server returned a HTTP/2 error.";
295 return "Server returned a HTTP/2 stream error.";
297 return std::string();
305 if ( it != d->_extraInfo.end() ) {
307 return boost::any_cast<std::string>( it->second );
308 }
catch (
const boost::bad_any_cast &) { }
312 if ( it != d->_extraInfo.end() ) {
314 return boost::any_cast<std::string>( it->second );
315 }
catch (
const boost::bad_any_cast &) { }
318 return std::string();
const char * c_str() const
String representation.
static std::string typeToString(NetworkRequestError::Type t)
NetworkRequestErrorPrivate(NetworkRequestError::Type code, std::string &&msg, std::map< std::string, boost::any > &&extraInfo)
static zyppng::NetworkRequestError fromCurlMError(int nativeCode)
NetworkRequestErrorPrivate * clone() const
static zyppng::NetworkRequestError fromCurlError(NetworkRequest &req, int nativeCode, const std::string &nativeError)
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})
The NetworkRequestError class Represents a error that occured in.
std::string toString() const
toString Returns a string representation of the error
const std::map< std::string, boost::any > & extraInfo() const
Type type() const
type Returns the type of the error
std::string nativeErrorString() const
bool isError() const
isError Will return true if this is a actual error
const zypp::Pathname & targetFilePath() const
Returns the target filename path.
void * nativeHandle() const
TransferSettings & transferSettings()
const std::string & lastRedirectInfo() const
std::string numstring(char n, int w=0)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
constexpr std::string_view CurlNativeErrorDescKey
constexpr std::string_view CurlNativeErrorCodeDescKey
ZYPP_IMPL_PRIVATE(Provide)