MySQL 9.3.0
Source Code Documentation
error.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_REST_MRS_SRC_MRS_REST_ERROR_H_
27#define ROUTER_SRC_REST_MRS_SRC_MRS_REST_ERROR_H_
28
29#include <string>
30
31#include "http/base/request.h"
33
34namespace mrs {
35namespace http {
36
37class Error {
38 public:
40
41 public:
42 template <typename... T>
43 Error(const Status s, const std::string &m, const T &...t) : status{s} {
44 message = (m + ... + t);
45 }
46
47 Error(const Status s)
50 std::string message;
51};
52
54 public:
56
57 virtual const char *name() const = 0;
58 virtual bool retry() const = 0;
59 virtual Error change_response(::http::base::Request *request) const = 0;
60};
61
63 public:
64 using Headers = std::vector<std::pair<std::string, std::string>>;
65
67 : status_code_{status_code}, headers_{headers} {}
68
69 const char *name() const override { return "ErrorWithHttpHeaders"; }
70 bool retry() const override { return false; }
71 Error change_response(::http::base::Request *request) const override {
72 for (auto [k, v] : headers_) {
73 request->get_output_headers().add(k.c_str(), v.c_str());
74 }
75
76 return Error(status_code_);
77 }
78
79 private:
82};
83
85 public:
86 ErrorRedirect(const std::string &redirect, const bool permanent = false)
87 : redirect_{redirect}, permanent_{permanent} {}
88
89 const char *name() const override { return "ErrorRedirect"; }
90 bool retry() const override { return false; }
91 Error change_response(::http::base::Request *request) const override {
92 request->get_output_headers().add("Location", redirect_.c_str());
95 }
96
97 private:
98 std::string redirect_;
100};
101
102} // namespace http
103} // namespace mrs
104
105#endif // ROUTER_SRC_REST_MRS_SRC_MRS_REST_ERROR_H_
virtual void add(const std::string_view &key, std::string &&value)
Definition: headers.cc:47
Definition: request.h:44
virtual Headers & get_output_headers()=0
Definition: error.h:53
virtual Error change_response(::http::base::Request *request) const =0
virtual const char * name() const =0
virtual bool retry() const =0
virtual ~ErrorChangeResponse()
Definition: error.h:55
Definition: error.h:84
Error change_response(::http::base::Request *request) const override
Definition: error.h:91
ErrorRedirect(const std::string &redirect, const bool permanent=false)
Definition: error.h:86
const char * name() const override
Definition: error.h:89
bool permanent_
Definition: error.h:99
bool retry() const override
Definition: error.h:90
std::string redirect_
Definition: error.h:98
Definition: error.h:62
bool retry() const override
Definition: error.h:70
ErrorWithHttpHeaders(HttpStatusCode::key_type status_code, Headers headers)
Definition: error.h:66
std::vector< std::pair< std::string, std::string > > Headers
Definition: error.h:64
Headers headers_
Definition: error.h:81
HttpStatusCode::key_type status_code_
Definition: error.h:80
const char * name() const override
Definition: error.h:69
Error change_response(::http::base::Request *request) const override
Definition: error.h:71
Definition: error.h:37
Status status
Definition: error.h:49
::http::base::status_code::key_type Status
Definition: error.h:39
Error(const Status s)
Definition: error.h:47
Error(const Status s, const std::string &m, const T &...t)
Definition: error.h:43
std::string message
Definition: error.h:50
#define T
Definition: jit_executor_value.cc:373
Definition: status_code.h:111
auto get_default_status_text(key_type status)
Definition: status_code.h:114
int key_type
Definition: method.h:38
int key_type
Definition: status_code.h:36
constexpr key_type TemporaryRedirect
Definition: status_code.h:61
constexpr key_type PermanentRedirect
Definition: status_code.h:62
Definition: connection.h:55
HttpStatusCode::key_type redirect(HttpRequest *request, const char *url)
Definition: utilities.cc:39
Definition: authorize_manager.h:48