00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef restcgi_exception_h
00023 #define restcgi_exception_h
00024 #include "apidefs.h"
00025 #include "status_code_e.h"
00026 #include <string>
00027 #include <map>
00028 #include <exception>
00029 #ifdef _WIN32
00030 #pragma warning (disable: 4251)
00031 #endif
00032 namespace restcgi {
00055 class RESTCGI_API exception : public std::exception {
00056 public:
00057 typedef std::map<std::string, std::string> map_type;
00058
00059
00060 exception(const status_code_e& sc, const std::string& errmsg = "") throw();
00061 ~exception() throw();
00062 const status_code_e& status_code() const throw() {return status_code_;}
00063
00064
00065 const char* what() const throw() {return what_.c_str();}
00066 const std::string& errmsg() const {return errmsg_;}
00067
00068
00069 virtual bool inhibit_content() const {return false;}
00070 const map_type& map() const {return map_;}
00071 map_type& map() {return map_;}
00072
00073
00074
00075
00076 bool insert(const std::string& name, const std::string& value);
00077 virtual void copy_hdr_flds(map_type& map) const {}
00078 static const char* VARIABLE_NAME_PREFIX;
00079 protected:
00080 bool exception_insert(const std::string& name, const std::string& value);
00081 private:
00082 status_code_e status_code_;
00083 std::string errmsg_;
00084 std::string what_;
00085 map_type map_;
00086 };
00091 class RESTCGI_API no_content : public exception {
00092 public:
00093 no_content() throw();
00094 ~no_content() throw();
00095 bool inhibit_content() const {return true;}
00096 static const status_code_e STATUS_CODE;
00097 };
00102 class RESTCGI_API reset_content : public exception {
00103 public:
00104 reset_content() throw();
00105 ~reset_content() throw();
00106 bool inhibit_content() const {return true;}
00107 static const status_code_e STATUS_CODE;
00108 };
00111 class RESTCGI_API see_other : public exception {
00112 public:
00114 see_other(const std::string& location) throw();
00115 ~see_other() throw();
00116 void copy_hdr_flds(map_type& map) const;
00117 const std::string& location() const {return location_;}
00118 static const status_code_e STATUS_CODE;
00119 private:
00120 std::string location_;
00121 };
00126 class RESTCGI_API not_modified : public exception {
00127 public:
00129 not_modified(const std::string& etag = "") throw();
00130 ~not_modified() throw();
00131 bool inhibit_content() const {return true;}
00132 void copy_hdr_flds(map_type& map) const;
00133 const std::string& etag() const {return etag_;}
00134 static const status_code_e STATUS_CODE;
00135 private:
00136 std::string etag_;
00137 };
00140 class RESTCGI_API bad_request : public exception {
00141 public:
00143 bad_request(const std::string& errmsg) throw();
00144 static const status_code_e STATUS_CODE;
00145 };
00148 class RESTCGI_API unauthorized : public exception {
00149 public:
00151 unauthorized(const std::string& errmsg) throw();
00152 static const status_code_e STATUS_CODE;
00153 };
00156 class RESTCGI_API not_found : public exception {
00157 public:
00159 not_found(const std::string& uri_path_rem) throw();
00160 ~not_found() throw();
00163 const std::string& uri_path_rem() const {return uri_path_rem_;}
00164 static const status_code_e STATUS_CODE;
00165 private:
00166 std::string uri_path_rem_;
00167 };
00170 class RESTCGI_API method_not_allowed : public exception {
00171 public:
00173 method_not_allowed(const std::string& allow) throw();
00174 ~method_not_allowed() throw();
00175 void copy_hdr_flds(map_type& map) const;
00176 const std::string& allow() const {return allow_;}
00177 static const status_code_e STATUS_CODE;
00178 private:
00179 std::string allow_;
00180 };
00183 class RESTCGI_API conflict : public exception {
00184 public:
00186 conflict(const std::string& errmsg) throw();
00187 static const status_code_e STATUS_CODE;
00188 };
00191 class RESTCGI_API gone : public exception {
00192 public:
00194 gone(const std::string& errmsg = "") throw();
00195 static const status_code_e STATUS_CODE;
00196 };
00199 class RESTCGI_API precondition_failed : public exception {
00200 public:
00202 precondition_failed(const std::string& errmsg) throw();
00203 static const status_code_e STATUS_CODE;
00204 };
00207 class RESTCGI_API request_entity_too_large : public exception {
00208 public:
00210 request_entity_too_large(const std::string& errmsg) throw();
00211 static const status_code_e STATUS_CODE;
00212 };
00215 class RESTCGI_API unsupported_media_type : public exception {
00216 public:
00218 unsupported_media_type(const std::string& errmsg = "") throw();
00219 static const status_code_e STATUS_CODE;
00220 };
00223 class RESTCGI_API internal_server_error : public exception {
00224 public:
00226 internal_server_error(const std::string& errmsg = "") throw();
00227 static const status_code_e STATUS_CODE;
00228 };
00229 }
00230 #endif