bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HttpError.h
1// -*- mode: c++; c-basic-offset:4 -*-
2//
3// This file is part of the BES http package, part of the Hyrax data server.
4//
5// Copyright (c) 2024 OPeNDAP, Inc.
6// Author: Nathan Potter <ndp@opendap.org>
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Lesser General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21//
22// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23//
24// Authors:
25// ndp Nathan Potter <ndp@opendap.org>
26
27#ifndef BES_HTTPERROR_H
28#define BES_HTTPERROR_H
29
30#include <string>
31#include <utility>
32#include <vector>
33#include <sstream>
34
35#include <curl/curl.h>
36
37#include "BESInfo.h"
38#include "BESError.h"
39
40namespace http {
41
42class HttpError : public BESError {
43 CURLcode d_curl_code = CURLE_OK;
44 long d_http_status = 200;
45 std::string d_origin_url;
46 std::string d_redirect_url;
47 std::vector<std::string> d_response_headers;
48 std::string d_response_body;
49
50public:
51 HttpError() = default;
52
53 HttpError(const std::string &msg,
54 const CURLcode code,
55 const long http_status,
56 const std::string &origin_url,
57 const std::string &redirect_url,
58 const std::vector<std::string> &response_headers,
59 const std::string &response_body,
60 const std::string &file,
61 const int line) :
62 BESError(msg, BES_HTTP_ERROR, file, line),
63 d_curl_code(code),
64 d_http_status(http_status),
65 d_origin_url(origin_url),
66 d_redirect_url(redirect_url),
67 d_response_headers(response_headers),
68 d_response_body(response_body) {};
69
70 HttpError(const std::string &msg,
71 const CURLcode code,
72 const long http_status,
73 const std::string &origin_url,
74 const std::string &redirect_url,
75 const std::string &file,
76 const int line) :
77 BESError(msg, BES_HTTP_ERROR, file, line),
78 d_curl_code(code),
79 d_http_status(http_status),
80 d_origin_url(origin_url),
81 d_redirect_url(redirect_url) {};
82
83 HttpError(std::string msg, std::string file, unsigned int line) :
84 BESError(std::move(msg), BES_HTTP_ERROR, std::move(file), line) {}
85
86 HttpError(const HttpError &src) = default;
87
88 ~HttpError() override = default;
89
90 std::string origin_url() const { return d_origin_url; }
91
92 std::string redirect_url() const { return d_redirect_url; }
93
94 CURLcode curl_code() const { return d_curl_code; }
95
96 long http_status() const { return d_http_status; }
97
98 std::vector<std::string> response_headers() const { return d_response_headers; }
99
100 std::string response_body() const { return d_response_body; }
101
102 void add_my_error_details_to(BESInfo &info) const override;
103
108 std::string dump() const;
109
118 void dump(std::ostream &strm) const override {
119 strm << dump();
120 }
121
122 std::string error_name() const override { return "HttpError"; }
123};
124
125} // http
126
127#endif //BES_HTTPERROR_H
informational response object
Definition BESInfo.h:63
void add_my_error_details_to(BESInfo &info) const override
Definition HttpError.cc:14
void dump(std::ostream &strm) const override
dumps information about this object
Definition HttpError.h:118
std::string dump() const
Returns a string describing this object and its state.
Definition HttpError.cc:28
utility class for the HTTP catalog module
Definition TheBESKeys.h:51