Skip to content

Commit

Permalink
Merge pull request #211 from mmd-osm/patch/issue_210
Browse files Browse the repository at this point in the history
Prepend HTTP 412 error text w/ Precondition failed: for Rails port compatibility
  • Loading branch information
mmd-osm authored Jan 3, 2020
2 parents 00725b0 + 9613776 commit 1377de5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/cgimap/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down
5 changes: 4 additions & 1 deletion src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
4 changes: 2 additions & 2 deletions test/test_parse_osmchange_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1377de5

Please # to comment.