Skip to content

Commit

Permalink
custom 400 HTTPError.reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneplus committed Jan 15, 2014
1 parent 95d95c4 commit 9044515
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/server/ltp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,17 @@ static int Service(struct mg_connection *conn) {
string strSentence = sentence;

// validation check
if (strlen(sentence) == 0 || !isclear(strSentence)) {
if (strlen(sentence) == 0) {
WARNING_LOG("Input sentence is empty");
std::string response = "HTTP/1.1 400 Empty sentence\r\n\r\n";
mg_printf(conn, "%s", response.c_str());
return 0;
}

if (!isclear(strSentence)) {
WARNING_LOG("Failed string validation check");
// Input sentence is not clear
std::string response = "HTTP/1.1 400 Bad Request\r\n\r\n";
response += "Input string not well formated";
std::string response = "HTTP/1.1 400 Encoding not in UTF8\r\n\r\n";
mg_printf(conn, "%s", response.c_str());
return 0;
}
Expand All @@ -138,7 +144,7 @@ static int Service(struct mg_connection *conn) {
if(str_xml == "y") {
if (-1 == xml4nlp.LoadXMLFromString(strSentence)) {
// Failed the xml validation check
std::string response = "HTTP/1.1 400 Bad Request\r\n\r\n";
std::string response = "HTTP/1.1 400 Bad XML format\r\n\r\n";
response += "Failed to load custom xml";
mg_printf(conn, "%s", response.c_str());
return 0;
Expand Down Expand Up @@ -175,9 +181,6 @@ static int Service(struct mg_connection *conn) {

xml4nlp.ClearDOM();
}

std::string response = "HTTP/1.1 500 Internal Server Error\r\n\r\n";
mg_printf(conn, "%s", response.c_str());
return 1;
}

0 comments on commit 9044515

Please sign in to comment.