| 104 | } |
| 105 | |
| 106 | static Poco::Net::HTTPResponse::HTTPStatus exceptionCodeToHTTPStatus(int exception_code) |
| 107 | { |
| 108 | using namespace Poco::Net; |
| 109 | |
| 110 | if (exception_code == ErrorCodes::REQUIRED_PASSWORD) |
| 111 | return HTTPResponse::HTTP_UNAUTHORIZED; |
| 112 | else if ( |
| 113 | exception_code == ErrorCodes::CANNOT_PARSE_TEXT || exception_code == ErrorCodes::CANNOT_PARSE_ESCAPE_SEQUENCE |
| 114 | || exception_code == ErrorCodes::CANNOT_PARSE_QUOTED_STRING || exception_code == ErrorCodes::CANNOT_PARSE_DATE |
| 115 | || exception_code == ErrorCodes::CANNOT_PARSE_DATETIME || exception_code == ErrorCodes::CANNOT_PARSE_NUMBER) |
| 116 | return HTTPResponse::HTTP_BAD_REQUEST; |
| 117 | else if ( |
| 118 | exception_code == ErrorCodes::UNKNOWN_ELEMENT_IN_AST || exception_code == ErrorCodes::UNKNOWN_TYPE_OF_AST_NODE |
| 119 | || exception_code == ErrorCodes::TOO_DEEP_AST || exception_code == ErrorCodes::TOO_BIG_AST |
| 120 | || exception_code == ErrorCodes::UNEXPECTED_AST_STRUCTURE) |
| 121 | return HTTPResponse::HTTP_BAD_REQUEST; |
| 122 | else if (exception_code == ErrorCodes::SYNTAX_ERROR) |
| 123 | return HTTPResponse::HTTP_BAD_REQUEST; |
| 124 | else if ( |
| 125 | exception_code == ErrorCodes::UNKNOWN_TABLE || exception_code == ErrorCodes::UNKNOWN_FUNCTION |
| 126 | || exception_code == ErrorCodes::UNKNOWN_IDENTIFIER || exception_code == ErrorCodes::UNKNOWN_TYPE |
| 127 | || exception_code == ErrorCodes::UNKNOWN_STORAGE || exception_code == ErrorCodes::UNKNOWN_DATABASE |
| 128 | || exception_code == ErrorCodes::UNKNOWN_SETTING || exception_code == ErrorCodes::UNKNOWN_DIRECTION_OF_SORTING |
| 129 | || exception_code == ErrorCodes::UNKNOWN_AGGREGATE_FUNCTION || exception_code == ErrorCodes::UNKNOWN_FORMAT |
| 130 | || exception_code == ErrorCodes::UNKNOWN_DATABASE_ENGINE) |
| 131 | return HTTPResponse::HTTP_NOT_FOUND; |
| 132 | else if (exception_code == ErrorCodes::UNKNOWN_TYPE_OF_QUERY) |
| 133 | return HTTPResponse::HTTP_NOT_FOUND; |
| 134 | else if (exception_code == ErrorCodes::QUERY_IS_TOO_LARGE) |
| 135 | return HTTPResponse::HTTP_REQUESTENTITYTOOLARGE; |
| 136 | else if (exception_code == ErrorCodes::NOT_IMPLEMENTED) |
| 137 | return HTTPResponse::HTTP_NOT_IMPLEMENTED; |
| 138 | else if (exception_code == ErrorCodes::SOCKET_TIMEOUT || exception_code == ErrorCodes::CANNOT_OPEN_FILE) |
| 139 | return HTTPResponse::HTTP_SERVICE_UNAVAILABLE; |
| 140 | else if (exception_code == ErrorCodes::HTTP_LENGTH_REQUIRED) |
| 141 | return HTTPResponse::HTTP_LENGTH_REQUIRED; |
| 142 | |
| 143 | return HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; |
| 144 | } |
| 145 | |
| 146 | void APIRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response) |
| 147 | { |
no outgoing calls
no test coverage detected