OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
BESDapError.cc
Go to the documentation of this file.
1
// BESDapError.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
#include <iostream>
35
36
using
std::ostringstream;
37
38
#include "
BESDapError.h
"
39
#include "
BESContextManager.h
"
40
#include "
BESDapErrorInfo.h
"
41
64
int
65
BESDapError::convert_error_code
(
int
error_code,
int
current_error_type )
66
{
67
if
( current_error_type ==
BES_INTERNAL_FATAL_ERROR
)
68
return
current_error_type ;
69
switch
( error_code )
70
{
71
case
undefined_error:
72
case
unknown_error:
73
{
74
return
BES_INTERNAL_ERROR
;
75
break ;
76
}
77
case
internal_error:
78
{
79
return
BES_INTERNAL_FATAL_ERROR
;
80
break ;
81
}
82
case
no_such_file:
83
{
84
return
BES_NOT_FOUND_ERROR
;
85
break ;
86
}
87
case
no_such_variable:
88
case
malformed_expr:
89
{
90
return
BES_SYNTAX_USER_ERROR
;
91
break ;
92
}
93
case
no_authorization:
94
case
cannot_read_file:
95
case
dummy_message:
96
{
97
return
BES_FORBIDDEN_ERROR
;
98
break ;
99
}
100
default
:
101
{
102
return
BES_INTERNAL_ERROR
;
103
break ;
104
}
105
}
106
return
BES_INTERNAL_ERROR
;
107
}
108
118
int
119
BESDapError::handleException
(
BESError
&e,
BESDataHandlerInterface
&dhi )
120
{
121
// If we are handling errors in a dap2 context, then create a
122
// DapErrorInfo object to transmit/print the error as a dap2
123
// response.
124
bool
found = false ;
125
// I changed 'dap_format' to 'errors' in the following line. jhrg 10/6/08
126
string
context =
BESContextManager::TheManager
()->
get_context
(
"errors"
, found ) ;
127
if
( context ==
"dap2"
)
128
{
129
ErrorCode ec = unknown_error ;
130
BESDapError
*de =
dynamic_cast<
BESDapError
*
>
( &e);
131
if
( de )
132
{
133
ec = de->
get_error_code
() ;
134
}
135
e.
set_error_type
(
convert_error_code
( ec, e.
get_error_type
() ) ) ;
136
dhi.
error_info
=
new
BESDapErrorInfo
( ec, e.
get_message
() ) ;
137
138
return
e.
get_error_type
() ;
139
}
140
else
141
{
142
// If we are not in a dap2 context and the exception is a dap
143
// handler exception, then convert the error message to include the
144
// error code. If it is or is not a dap exception, we simply return
145
// that the exception was not handled.
146
BESError
*e_p = &e ;
147
BESDapError
*de =
dynamic_cast<
BESDapError
*
>
( e_p );
148
if
( de )
149
{
150
ostringstream s;
151
s <<
"libdap exception building response"
152
<<
": error_code = "
<< de->
get_error_code
()
153
<<
": "
<< de->
get_message
() ;
154
e.
set_message
( s.str() ) ;
155
e.
set_error_type
(
convert_error_code
( de->
get_error_code
(),
156
e.
get_error_type
() ) ) ;
157
}
158
}
159
return
0 ;
160
}
161
168
void
169
BESDapError::dump
( ostream &strm )
const
170
{
171
strm <<
BESIndent::LMarg
<<
"BESDapError::dump - ("
172
<< (
void
*)
this
<<
")"
<< endl ;
173
BESIndent::Indent
() ;
174
strm <<
BESIndent::LMarg
<<
"error code = "
<<
get_error_code
() << endl ;
175
BESError::dump
( strm ) ;
176
BESIndent::UnIndent
() ;
177
}
178
dispatch
BESDapError.cc
Generated by
1.8.3.1