00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef TNT_HTTPERROR_H
00031 #define TNT_HTTPERROR_H
00032
00033 #include <stdexcept>
00034 #include <string>
00035 #include <tnt/httpmessage.h>
00036
00037 namespace tnt
00038 {
00039 class HttpReturn
00040 {
00041 unsigned returncode;
00042 const char* msg;
00043
00044 public:
00045 explicit HttpReturn(unsigned errcode);
00046 HttpReturn(unsigned errcode_, const char* msg_);
00047
00048 unsigned getReturnCode() const
00049 { return returncode; }
00050
00051 const char* getMessage() const
00052 { return msg; }
00053
00054 static const char* httpMessage(unsigned httpstatus);
00055 };
00056
00058 class HttpError : public std::exception, public HttpMessage
00059 {
00060 std::string msg;
00061 std::string body;
00062
00063 public:
00064 explicit HttpError(unsigned errcode);
00065 HttpError(unsigned errcode, const std::string& msg);
00066 HttpError(unsigned errcode, const std::string& msg, const std::string& b);
00067 ~HttpError() throw() { }
00068
00069 const char* what() const throw ()
00070 { return msg.c_str(); }
00071
00072 std::string getErrcodeStr() const
00073 { return msg.substr(0, 3); }
00074
00075 unsigned getErrcode() const
00076 {
00077 return (msg[0] - '0') * 100
00078 + (msg[1] - '0') * 10
00079 + (msg[2] - '0');
00080 }
00081
00082 std::string getErrmsg() const;
00083
00085 const std::string& getBody() const { return body; }
00086 };
00087
00089 class NotFoundException : public HttpError
00090 {
00091 std::string url;
00092
00093 public:
00094 explicit NotFoundException(const std::string& url_);
00095 ~NotFoundException() throw() { }
00096
00097 const std::string& getUrl() const { return url; }
00098 };
00099
00100 class NotAuthorized : public HttpError
00101 {
00102 public:
00103 explicit NotAuthorized(const std::string& realm);
00104 };
00105
00106 class MovedTemporarily : public HttpError
00107 {
00108 public:
00109 explicit MovedTemporarily(const std::string& url);
00110 };
00111 }
00112
00113 #endif // TNT_HTTPERROR_H