|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
// -*- mode: c++; c-basic-offset:4 -*-
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
|
|
Packit |
a4aae4 |
// Access Protocol.
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
// Copyright (c) 2002,2003 OPeNDAP, Inc.
|
|
Packit |
a4aae4 |
// Author: James Gallagher <jgallagher@opendap.org>
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// This library is free software; you can redistribute it and/or
|
|
Packit |
a4aae4 |
// modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a4aae4 |
// License as published by the Free Software Foundation; either
|
|
Packit |
a4aae4 |
// version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// This library is distributed in the hope that it will be useful,
|
|
Packit |
a4aae4 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a4aae4 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a4aae4 |
// Lesser General Public License for more details.
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a4aae4 |
// License along with this library; if not, write to the Free Software
|
|
Packit |
a4aae4 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
// (c) COPYRIGHT URI/MIT 1999,2000
|
|
Packit |
a4aae4 |
// Please read the full copyright statement in the file COPYRIGHT_URI.
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// Authors:
|
|
Packit |
a4aae4 |
// jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
// Interface for the Error class
|
|
Packit |
a4aae4 |
//
|
|
Packit |
a4aae4 |
// jhrg 4/23/96
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
#ifndef _error_h
|
|
Packit |
a4aae4 |
#define _error_h
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
#include <cstdio> // For FILE *
|
|
Packit |
a4aae4 |
#include <iostream>
|
|
Packit |
a4aae4 |
#include <string>
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
using std::cout;
|
|
Packit |
a4aae4 |
using std::string;
|
|
Packit |
a4aae4 |
using std::ostream;
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
namespace libdap
|
|
Packit |
a4aae4 |
{
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
/** The most common errors within DAP2 have special codes so that they
|
|
Packit |
a4aae4 |
can be spotted easily by the client software. Any error
|
|
Packit |
a4aae4 |
without a matching code gets the <tt>unknown_error</tt> code.
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
@brief An enumerated type for common errors. */
|
|
Packit |
a4aae4 |
typedef int ErrorCode; //using standard errno+netCDF error codes from server
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
/** @name Internal DAP errors */
|
|
Packit |
a4aae4 |
//@{
|
|
Packit |
a4aae4 |
#define undefined_error 1000 ///< Undefined error code, an empty Error object was built
|
|
Packit |
a4aae4 |
#define unknown_error 1001 ///< Unknown error (the default code) (HTTP 400)
|
|
Packit |
a4aae4 |
#define internal_error 1002 ///< Internal server error (500)
|
|
Packit |
a4aae4 |
#define no_such_file 1003 ///< (400)
|
|
Packit |
a4aae4 |
#define no_such_variable 1004 ///< (400)
|
|
Packit |
a4aae4 |
#define malformed_expr 1005 ///< (400)
|
|
Packit |
a4aae4 |
#define no_authorization 1006 ///< (401)
|
|
Packit |
a4aae4 |
#define cannot_read_file 1007 ///< (400)
|
|
Packit |
a4aae4 |
#define not_implemented 1008 ///< Implies that it will/might be impl. (501)
|
|
Packit |
a4aae4 |
#define dummy_message 1009 ///< @see Error.cc; end the array with ""
|
|
Packit |
a4aae4 |
//@}
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
/** The Error class is used to transport error information from the server to
|
|
Packit |
a4aae4 |
the client within libdap. This class is also the base class for all the
|
|
Packit |
a4aae4 |
errors thrown by methods in the DAP, so catching Error will catch all DAP
|
|
Packit |
a4aae4 |
throws. Errors consist of an error code and a string. The code can be
|
|
Packit |
a4aae4 |
used to quickly distinguish between certain common errors while the
|
|
Packit |
a4aae4 |
string is used to convey information about the error to the user. The
|
|
Packit |
a4aae4 |
error code should never be displayed to the user.
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
This class is used on both clients and servers. The \e print() and \e
|
|
Packit |
a4aae4 |
parse() methods are used to send the object back and forth.
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
@note A past version of this class supported the notion of an error
|
|
Packit |
a4aae4 |
correcting program (Tcl, Java, ...) that could be sent from the server to
|
|
Packit |
a4aae4 |
the client to help users correct the error and resubmit the request. This
|
|
Packit |
a4aae4 |
never worked well in practice and that feature of the class is deprecated.
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
@brief A class for error processing.
|
|
Packit |
a4aae4 |
@author jhrg */
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
class Error
|
|
Packit |
a4aae4 |
{
|
|
Packit |
a4aae4 |
protected:
|
|
Packit |
a4aae4 |
ErrorCode _error_code;
|
|
Packit |
a4aae4 |
string _error_message;
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
public:
|
|
Packit |
a4aae4 |
Error(ErrorCode ec, string msg);
|
|
Packit |
a4aae4 |
Error(string msg);
|
|
Packit |
a4aae4 |
Error();
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
Error(const Error ©_from);
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
virtual ~Error();
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
Error &operator=(const Error &rhs;;
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
bool OK() const;
|
|
Packit |
a4aae4 |
bool parse(FILE *fp);
|
|
Packit |
a4aae4 |
void print(FILE *out) const;
|
|
Packit |
a4aae4 |
void print(ostream &out) const;
|
|
Packit |
a4aae4 |
ErrorCode get_error_code() const;
|
|
Packit |
a4aae4 |
string get_error_message() const;
|
|
Packit |
a4aae4 |
void set_error_code(ErrorCode ec = undefined_error);
|
|
Packit |
a4aae4 |
void set_error_message(string msg = "");
|
|
Packit |
a4aae4 |
};
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
} // namespace libdap
|
|
Packit |
a4aae4 |
|
|
Packit |
a4aae4 |
#endif // _error_h
|