37 #include "BESExceptionManager.h" 40 #include "TheBESKeys.h" 41 #include "BESInfoList.h" 44 #define DEFAULT_ADMINISTRATOR "support@opendap.org" 48 BESExceptionManager::BESExceptionManager()
52 BESExceptionManager::~BESExceptionManager()
71 _ehm_list.push_back(ehm);
82 time_t timer = time(NULL);
84 string now(asctime(ptm));
85 now = now.substr(0, now.length() - 1);
88 string error_name =
"";
91 bool only_log_to_verbose =
false;
93 case BES_INTERNAL_FATAL_ERROR:
94 error_name =
"BES Internal Fatal Error";
97 case BES_INTERNAL_ERROR:
98 error_name =
"BES Internal Error";
101 case BES_SYNTAX_USER_ERROR:
102 error_name =
"BES User Syntax Error";
103 only_log_to_verbose =
false;
106 case BES_FORBIDDEN_ERROR:
107 error_name =
"BES Forbidden Error";
110 case BES_NOT_FOUND_ERROR:
111 error_name =
"BES Not Found Error";
112 only_log_to_verbose =
false;
116 error_name =
"Unrecognized BES Error";
121 string m = BESLog::mark;
122 std::ostringstream msg;
123 msg <<
"ERROR: " << error_name << m <<
"type: " << e.
get_error_type() << m <<
"file: " << e.
get_file() << m
127 if (only_log_to_verbose) {
133 BESLog::TheLog()->flush_me();
134 *(BESLog::TheLog()) << msg.str() << endl;
135 BESLog::TheLog()->flush_me();
139 LOG(
"ERROR: " << error_name <<
": " << e.
get_message() << endl);
141 BESLog::TheLog()->flush_me();
142 *(BESLog::TheLog()) << msg.str() << endl;
143 BESLog::TheLog()->flush_me();
173 for (ehm_iter i = _ehm_list.begin(), ei = _ehm_list.end(); i != ei; ++i) {
175 int handled = p(e, dhi);
181 dhi.
error_info = BESInfoList::TheList()->build_info();
182 string action_name = dhi.action_name;
183 if (action_name.empty()) action_name =
"BES";
186 string administrator =
"";
190 string key =
"BES.ServerAdministrator";
194 administrator = DEFAULT_ADMINISTRATOR;
196 if (administrator.empty()) {
197 administrator = DEFAULT_ADMINISTRATOR;
219 strm << BESIndent::LMarg <<
"BESExceptionManager::dump - (" << (
void *)
this <<
")" << endl;
221 strm << BESIndent::LMarg <<
"# registered callbacks: " << _ehm_list.size() << endl;
222 BESIndent::UnIndent();
226 BESExceptionManager::TheEHM()
228 if (_instance == 0) {
virtual void add_ehm_callback(p_bes_ehm ehm)
Register an exception handler with the manager.
virtual std::string get_message()
get the error message for this exception
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
virtual int get_error_type()
Return the return code for this error class.
Abstract exception class for the BES with basic string message.
static TheBESKeys * TheKeys()
virtual void add_exception(BESError &e, const string &admin)
add exception information to this informational object
manages exception handling code and default exceptions
Structure storing information used by the BES to handle the request.
virtual std::string get_file()
get the file name where the exception was thrown
virtual void dump(ostream &strm) const
dumps information about this object
virtual void begin_response(const string &response_name, BESDataHandlerInterface &dhi)
begin the informational response
BESInfo * error_info
error information object
virtual int handle_exception(BESError &e, BESDataHandlerInterface &dhi)
Manage any exceptions thrown during the handling of a request.
virtual int get_line()
get the line number where the exception was thrown