Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prepend HTTP 412 error text w/ Precondition failed: for Rails port compatibility #211

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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