Browse Source

only return simple respones when something is wrong

master
Jørgen Sverre Lien Sellæg 5 years ago
parent
commit
c9927379f6
  1. 4
      include/http.hpp
  2. 21
      src/http.cpp

4
include/http.hpp

@ -8,10 +8,6 @@ const auto header_access_control =
class response { class response {
public: public:
static void https_required(std::shared_ptr<HttpServer::Response> response);
static void https_required(std::shared_ptr<HttpsServer::Response> response);
static void bad_json(std::shared_ptr<HttpServer::Response> response);
static void bad_json(std::shared_ptr<HttpsServer::Response> response);
static void bad_request(std::shared_ptr<HttpServer::Response> response); static void bad_request(std::shared_ptr<HttpServer::Response> response);
static void bad_request(std::shared_ptr<HttpsServer::Response> response); static void bad_request(std::shared_ptr<HttpsServer::Response> response);
static void not_found(std::shared_ptr<HttpServer::Response> response); static void not_found(std::shared_ptr<HttpServer::Response> response);

21
src/http.cpp

@ -1,29 +1,12 @@
#include <http.hpp> #include <http.hpp>
#include <json.hpp> #include <json.hpp>
// const auto https_required_msg = json::object({
// {"message", "100: Your server is configured to use https, but a "
// "request on http was received."},
// });
// const auto bad_json_msg = json::object({
// {"message", "101: Your request was not a valid JSON document."},
// });
const auto bad_object_msg = json::object({
{"message", "102: Your request was not a valid store."},
});
void response::bad_request(std::shared_ptr<HttpServer::Response> response) { void response::bad_request(std::shared_ptr<HttpServer::Response> response) {
return response->write(Status::client_error_bad_request, return response->write(Status::client_error_bad_request);
bad_object_msg.dump(),
{header_access_control, header_application_data});
} }
void response::bad_request(std::shared_ptr<HttpsServer::Response> response) { void response::bad_request(std::shared_ptr<HttpsServer::Response> response) {
return response->write(Status::client_error_bad_request, return response->write(Status::client_error_bad_request);
bad_object_msg.dump(),
{header_access_control, header_application_data});
} }
void response::not_found(std::shared_ptr<HttpsServer::Response> response) { void response::not_found(std::shared_ptr<HttpsServer::Response> response) {

Loading…
Cancel
Save