BESDapError.cc
Go to the documentation of this file.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
00031
00032
00033 #include <sstream>
00034
00035 using std::ostringstream;
00036
00037 #include "BESDapError.h"
00038 #include "BESContextManager.h"
00039 #include "BESDapErrorInfo.h"
00040
00063 int
00064 BESDapError::convert_error_code( int error_code, int current_error_type )
00065 {
00066 if( current_error_type == BES_INTERNAL_FATAL_ERROR )
00067 return current_error_type ;
00068 switch( error_code )
00069 {
00070 case undefined_error:
00071 case unknown_error:
00072 {
00073 return BES_INTERNAL_ERROR ;
00074 break ;
00075 }
00076 case internal_error:
00077 {
00078 return BES_INTERNAL_FATAL_ERROR ;
00079 break ;
00080 }
00081 case no_such_file:
00082 {
00083 return BES_NOT_FOUND_ERROR ;
00084 break ;
00085 }
00086 case no_such_variable:
00087 case malformed_expr:
00088 {
00089 return BES_SYNTAX_USER_ERROR ;
00090 break ;
00091 }
00092 case no_authorization:
00093 case cannot_read_file:
00094 case dummy_message:
00095 {
00096 return BES_FORBIDDEN_ERROR ;
00097 break ;
00098 }
00099 default:
00100 {
00101 return BES_INTERNAL_ERROR ;
00102 break ;
00103 }
00104 }
00105 return BES_INTERNAL_ERROR ;
00106 }
00107
00117 int
00118 BESDapError::handleException( BESError &e, BESDataHandlerInterface &dhi )
00119 {
00120
00121
00122
00123 bool found = false ;
00124
00125 string context = BESContextManager::TheManager()->get_context( "errors", found ) ;
00126 if( context == "dap2" )
00127 {
00128 ErrorCode ec = unknown_error ;
00129 BESDapError *de = dynamic_cast<BESDapError*>( &e);
00130 if( de )
00131 {
00132 ec = de->get_error_code() ;
00133 }
00134 e.set_error_type( convert_error_code( ec, e.get_error_type() ) ) ;
00135 dhi.error_info = new BESDapErrorInfo( ec, e.get_message() ) ;
00136
00137 return e.get_error_type() ;
00138 }
00139 else
00140 {
00141
00142
00143
00144
00145 BESDapError *de = dynamic_cast<BESDapError*>( &e);
00146 if( de )
00147 {
00148 ostringstream s;
00149 s << "libdap exception building response"
00150 << ": error_code = " << de->get_error_code()
00151 << ": " << de->get_message() ;
00152 e.set_message( s.str() ) ;
00153 e.set_error_type( convert_error_code( de->get_error_code(),
00154 e.get_error_type() ) ) ;
00155 }
00156 }
00157 return 0 ;
00158 }
00159