bes  Updated for version 3.20.13
BESDapError.cc
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 #include "BESDapError.h"
36 
37 using namespace std;
38 
39 BESDapError::BESDapError(string msg, bool fatal, libdap::ErrorCode ec, string file, unsigned int line) :
40  BESError(std::move(msg), 0, std::move(file), line), d_dap_error_code(ec)
41 {
42  set_bes_error_type(convert_error_code(ec, fatal));
43 }
44 
67 int BESDapError::convert_error_code(int error_code, int current_error_type)
68 {
69  if (current_error_type == BES_INTERNAL_FATAL_ERROR) return current_error_type;
70 
71  switch (error_code) {
72  case undefined_error:
73  case unknown_error: {
74  return BES_INTERNAL_ERROR;
75  }
76  case internal_error: {
77  return BES_INTERNAL_FATAL_ERROR;
78  }
79  case no_such_file: {
80  return BES_NOT_FOUND_ERROR;
81  }
82  case no_such_variable:
83  case malformed_expr: {
84  return BES_SYNTAX_USER_ERROR;
85  }
86  case no_authorization:
87  case cannot_read_file:
88  case dummy_message: {
89  return BES_FORBIDDEN_ERROR;
90  }
91  default: {
92  return BES_INTERNAL_ERROR;
93  }
94  }
95 }
96 
97 int BESDapError::convert_error_code(int error_code, bool fatal)
98 {
99  return convert_error_code(error_code, (fatal) ? BES_INTERNAL_FATAL_ERROR: BES_INTERNAL_ERROR);
100 }
101 
108 void BESDapError::dump(ostream &strm) const
109 {
110  strm << BESIndent::LMarg << "BESDapError::dump - (" << (void *) this << ")" << endl;
111  BESIndent::Indent();
112  strm << BESIndent::LMarg << "error code = " << get_dap_error_code() << endl;
113  BESError::dump(strm);
114  BESIndent::UnIndent();
115 }
static int convert_error_code(int error_code, int current_error_type)
converts the libdap error code to the bes error type
Definition: BESDapError.cc:67
virtual int get_dap_error_code() const
Definition: BESDapError.h:70
void dump(ostream &strm) const override
dumps information about this object
Definition: BESDapError.cc:108
Base exception class for the BES with basic string message.
Definition: BESError.h:59
void dump(std::ostream &strm) const override
Displays debug information about this object.
Definition: BESError.cc:59