libzypp  17.31.31
networkrequesterror.h
Go to the documentation of this file.
1 #ifndef ZYPP_NG_MEDIA_CURL_NETWORK_REQUEST_ERROR_H_INCLUDED
2 #define ZYPP_NG_MEDIA_CURL_NETWORK_REQUEST_ERROR_H_INCLUDED
3 
4 #include <zypp-core/zyppng/base/zyppglobal.h>
5 #include <zypp-core/base/PtrTypes.h>
6 #include <boost/any.hpp>
7 #include <string>
8 #include <map>
9 
10 namespace zyppng {
11 
12 class NetworkRequest;
13 class NetworkRequestErrorPrivate;
14 
23  class LIBZYPP_NG_EXPORT NetworkRequestError
24  {
25  public:
26  enum Type {
27  NoError = 0,
28  InternalError, //< A error in the dispatcher that is not caused by the backend, check the error string
29  Cancelled, //< The request was cancelled
30  PeerCertificateInvalid, //< the peer certificate validation failed
31  ConnectionFailed, //< connecting to the server failed
32  ExceededMaxLen, //< the downloaded data exceeded the requested maximum lenght
33  InvalidChecksum, //< The downloaded data has a different checksum than expected
34  UnsupportedProtocol, //< The protocol given in the URL scheme is not supported by the backend
35  MalformedURL, //< The given URL is malformed
36  TemporaryProblem, //< There was a temporary problem with the server side
37  Timeout, //< The request timed out
38  Forbidden, //< Accessing the requested ressource on the server was forbidden
39  NotFound, //< The requested path in the URL does not exist on the server
40  Unauthorized, //<< No auth data given but authorization required
41  AuthFailed, //<< Auth data was given, but authorization failed
42  ServerReturnedError, //<< A error was returned by the server that is not explicitly handled
43  MissingData, //<< The download was a multirange download and we did not get all data that was requested, if that is returned some ranges might have been downloaded successful
44  RangeFail, //<< The download was a multirange download but the server decided to return the full file.
45  Http2Error, //<< Special error code for HTTP2 related errors
46  Http2StreamError, //<< Special error code for HTTP2 stream related errors
47  };
48 
50 
55  Type type () const;
56 
61  std::string toString () const;
62 
67  bool isError () const;
68 
73  template<typename T>
74  T extraInfoValue ( const std::string &key, T &&defaultVal = T() ) const {
75  auto &t = extraInfo();
76  auto it = t.find(key);
77  if ( it != t.end() ) {
78  try {
79  return boost::any_cast<T>( it->second );
80  } catch ( const boost::bad_any_cast &) { }
81  }
82  return defaultVal;
83  }
84 
88  const std::map<std::string, boost::any> &extraInfo () const;
89 
93  std::string nativeErrorString() const;
94 
95  protected:
97 
98  private:
99  ZYPP_DECLARE_PRIVATE(NetworkRequestError)
100  zypp::RWCOW_pointer<NetworkRequestErrorPrivate> d_ptr;
101  };
102 }
103 
104 #endif
T extraInfoValue(const std::string &key, T &&defaultVal=T()) const
The NetworkRequestError class Represents a error that occured in.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1