MCPcopy Create free account
hub / github.com/ByConity/ByConity / trySendExceptionToClient

Function trySendExceptionToClient

src/Server/StaticRequestHandler.cpp:67–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67static inline void trySendExceptionToClient(
68 const std::string & s, int exception_code, HTTPServerRequest & request, HTTPServerResponse & response, WriteBuffer & out)
69{
70 try
71 {
72 response.set("X-ClickHouse-Exception-Code", toString<int>(exception_code));
73
74 /// If HTTP method is POST and Keep-Alive is turned on, we should read the whole request body
75 /// to avoid reading part of the current request body in the next request.
76 if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST
77 && response.getKeepAlive() && !request.getStream().eof() && exception_code != ErrorCodes::HTTP_LENGTH_REQUIRED)
78 request.getStream().ignore(std::numeric_limits<std::streamsize>::max());
79
80 response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
81
82 if (!response.sent())
83 *response.send() << s << std::endl;
84 else
85 {
86 if (out.count() != out.offset())
87 out.position() = out.buffer().begin();
88
89 writeString(s, out);
90 writeChar('\n', out);
91
92 out.next();
93 out.finalize();
94 }
95 }
96 catch (...)
97 {
98 tryLogCurrentException("StaticRequestHandler", "Cannot send exception to client");
99 }
100}
101
102void StaticRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response)
103{

Callers 3

handleRequestMethod · 0.85
handleRequestMethod · 0.85
handleRequestMethod · 0.85

Calls 15

writeStringFunction · 0.85
writeCharFunction · 0.85
tryLogCurrentExceptionFunction · 0.85
getStreamMethod · 0.80
sentMethod · 0.80
bufferMethod · 0.80
maxFunction · 0.50
setMethod · 0.45
eofMethod · 0.45
ignoreMethod · 0.45
sendMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected