From 96137765a62678254d67d4ffc7dae8f4826db76a Mon Sep 17 00:00:00 2001 From: mmd-osm Date: Thu, 17 Oct 2019 21:31:50 +0200 Subject: [PATCH] Prepend HTTP 412 error text w/ Precondition failed: for Rails port compatibility Fixes #210 --- include/cgimap/http.hpp | 3 +++ src/http.cpp | 5 ++++- test/test_parse_osmchange_input.cpp | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/cgimap/http.hpp b/include/cgimap/http.hpp index e0727e66a..094436904 100644 --- a/include/cgimap/http.hpp +++ b/include/cgimap/http.hpp @@ -131,6 +131,9 @@ class conflict : public exception { class precondition_failed : public exception { public: precondition_failed(const std::string &message); + const char *what() const noexcept; +private: + std::string fullstring; }; /** diff --git a/src/http.cpp b/src/http.cpp index ea89fb64f..27ca5a55c 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -95,7 +95,10 @@ conflict::conflict(const string &message) : exception(409, "Conflict", message) {} precondition_failed::precondition_failed(const string &message) - : exception(412, "Precondition Failed", message) {} + : exception(412, "Precondition Failed", message), + fullstring("Precondition failed: " + message) {} + +const char *precondition_failed::what() const noexcept { return fullstring.c_str(); } payload_too_large::payload_too_large(const string &message) : exception(413, "Payload Too Large", message) {} diff --git a/test/test_parse_osmchange_input.cpp b/test/test_parse_osmchange_input.cpp index f63a8df8e..c1ab81e94 100644 --- a/test/test_parse_osmchange_input.cpp +++ b/test/test_parse_osmchange_input.cpp @@ -640,11 +640,11 @@ void test_way() { } catch (http::exception &e) { if (e.code() != 412) throw std::runtime_error("test_way::010: Expected HTTP 412"); - const std::string expected = "Way -1 must have at least one node"; + const std::string expected = "Precondition failed: Way -1 must have at least one node"; const std::string actual = std::string(e.what()).substr(0, expected.size()); if (actual != expected) throw std::runtime_error( - "test_way::010: Expected Way -1 must have at least one node, got: " + actual); + "test_way::010: Expected Precondition failed: Way -1 must have at least one node, got: " + actual); } // Test node refs up to max number of nodes per way