make all error messages JSON
This commit is contained in:
parent
9894f2e053
commit
67efd150d4
@ -37,8 +37,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
namespace http {
|
namespace http {
|
||||||
|
|
||||||
const char okHTML[] = "";
|
const char okHTML[] = "";
|
||||||
const char badRequestHTML[] = "<html><head><title>Bad Request</title></head><body><h1>400 Bad Request</h1></body></html>";
|
const char badRequestHTML[] = "{\"status\": 400,\"status_message\":\"Bad Request\"}";
|
||||||
const char internalServerErrorHTML[] = "<html><head><title>Internal Server Error</title></head><body><h1>500 Internal Server Error</h1></body></html>";
|
const char internalServerErrorHTML[] = "{\"status\": 500,\"status_message\":\"Internal Server Error\"}";
|
||||||
const char seperators[] = { ':', ' ' };
|
const char seperators[] = { ':', ' ' };
|
||||||
const char crlf[] = { '\r', '\n' };
|
const char crlf[] = { '\r', '\n' };
|
||||||
const std::string okString = "HTTP/1.0 200 OK\r\n";
|
const std::string okString = "HTTP/1.0 200 OK\r\n";
|
||||||
|
@ -76,21 +76,15 @@ void RequestHandler::handle_request(const http::Request& req, http::Reply& rep){
|
|||||||
|
|
||||||
if ( !result || (it != request.end()) ) {
|
if ( !result || (it != request.end()) ) {
|
||||||
rep = http::Reply::StockReply(http::Reply::badRequest);
|
rep = http::Reply::StockReply(http::Reply::badRequest);
|
||||||
|
rep.content.clear();
|
||||||
const int position = std::distance(request.begin(), it);
|
const int position = std::distance(request.begin(), it);
|
||||||
|
rep.content.push_back(
|
||||||
|
"{\"status\":400,\"status_message\":\"Query string malformed close to position "
|
||||||
|
);
|
||||||
std::string tmp_position_string;
|
std::string tmp_position_string;
|
||||||
intToString(position, tmp_position_string);
|
intToString(position, tmp_position_string);
|
||||||
rep.content.push_back(
|
|
||||||
"Input seems to be malformed close to position "
|
|
||||||
"<br><pre>"
|
|
||||||
);
|
|
||||||
rep.content.push_back( request );
|
|
||||||
rep.content.push_back(tmp_position_string);
|
rep.content.push_back(tmp_position_string);
|
||||||
rep.content.push_back("<br>");
|
rep.content.push_back("\"}");
|
||||||
const unsigned end = std::distance(request.begin(), it);
|
|
||||||
for(unsigned i = 0; i < end; ++i) {
|
|
||||||
rep.content.push_back(" ");
|
|
||||||
}
|
|
||||||
rep.content.push_back("^<br></pre>");
|
|
||||||
} else {
|
} else {
|
||||||
//parsing done, lets call the right plugin to handle the request
|
//parsing done, lets call the right plugin to handle the request
|
||||||
BOOST_ASSERT_MSG(
|
BOOST_ASSERT_MSG(
|
||||||
|
Loading…
Reference in New Issue
Block a user