OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESShowErrorResponseHandler.cc
Go to the documentation of this file.
1 // BESShowErrorResponseHandler.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include <sstream>
34 
35 using std::istringstream ;
36 
38 #include "BESDataNames.h"
39 #include "BESInternalError.h"
40 #include "BESInternalFatalError.h"
41 #include "BESSyntaxUserError.h"
42 #include "BESForbiddenError.h"
43 #include "BESNotFoundError.h"
44 
46  : BESResponseHandler( name )
47 {
48 }
49 
51 {
52 }
53 
68 void
70 {
71  string etype_s = dhi.data[SHOW_ERROR_TYPE] ;
72  if( etype_s.empty() )
73  {
74  string err = dhi.action + " error type missing" ;
75  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
76  }
77  istringstream strm( etype_s ) ;
78  unsigned int etype = 0 ;
79  strm >> etype ;
80  if( !etype || etype > 5 )
81  {
82  string err = dhi.action + " invalid error type, should be 1-5" ;
83  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
84  }
85  switch( etype )
86  {
87  case BES_INTERNAL_ERROR:
88  {
89  string err = dhi.action + " Internal Error" ;
90  throw BESInternalError( err, __FILE__, __LINE__ ) ;
91  break ;
92  }
94  {
95  string err = dhi.action + " Internal Fatal Error" ;
96  throw BESInternalFatalError( err, __FILE__, __LINE__ ) ;
97  break ;
98  }
100  {
101  string err = dhi.action + " Syntax User Error" ;
102  throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
103  break ;
104  }
105  case BES_FORBIDDEN_ERROR:
106  {
107  string err = dhi.action + " Forbidden Error" ;
108  throw BESForbiddenError( err, __FILE__, __LINE__ ) ;
109  break ;
110  }
111  case BES_NOT_FOUND_ERROR:
112  {
113  string err = dhi.action + " Not Found Error" ;
114  throw BESNotFoundError( err, __FILE__, __LINE__ ) ;
115  break ;
116  }
117  }
118 }
119 
132 void
135 {
136  string err = "An exception should have been thrown, nothing to transmit" ;
137  throw BESInternalError( err, __FILE__, __LINE__ ) ;
138 }
139 
146 void
147 BESShowErrorResponseHandler::dump( ostream &strm ) const
148 {
149  strm << BESIndent::LMarg << "BESShowErrorResponseHandler::dump - ("
150  << (void *)this << ")" << endl ;
152  BESResponseHandler::dump( strm ) ;
154 }
155 
158 {
159  return new BESShowErrorResponseHandler( name ) ;
160 }
161 
#define BES_SYNTAX_USER_ERROR
Definition: BESError.h:44
error thrown if the resource requested cannot be found
exception thrown if an internal error is found and is fatal to the BES
exception thrown if inernal error encountered
#define BES_INTERNAL_ERROR
Definition: BESError.h:42
#define BES_FORBIDDEN_ERROR
Definition: BESError.h:45
static void Indent()
Definition: BESIndent.cc:38
error thrown if there is a user syntax error in the request or any other user error ...
static BESResponseHandler * ResponseBuilder(const string &name)
handler object that knows how to create a specific response object
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
#define BES_INTERNAL_FATAL_ERROR
Definition: BESError.h:43
error thrown if the BES is not allowed to access the resource requested
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
virtual void dump(ostream &strm) const
dumps information about this object
#define BES_NOT_FOUND_ERROR
Definition: BESError.h:46
virtual void execute(BESDataHandlerInterface &dhi)
throws a specific exception to test error handling in client
static void UnIndent()
Definition: BESIndent.cc:44
virtual void dump(ostream &strm) const
dumps information about this object
string action
the response object requested, e.g.
#define SHOW_ERROR_TYPE
Definition: BESDataNames.h:74
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command using the specified transmitter object ...