本文整理汇总了C++中ApiRequest::setResponseErrorJson方法的典型用法代码示例。如果您正苦于以下问题:C++ ApiRequest::setResponseErrorJson方法的具体用法?C++ ApiRequest::setResponseErrorJson怎么用?C++ ApiRequest::setResponseErrorJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiRequest
的用法示例。
在下文中一共展示了ApiRequest::setResponseErrorJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
api_return ApiRouter::handleRequest(ApiRequest& aRequest, bool aIsSecure, const WebSocketPtr& aSocket, const string& aIp) noexcept {
int code;
try {
// Special case because we may not have the session yet
if (aRequest.getApiModule() == "session") {
return handleSessionRequest(aRequest, aIsSecure, aSocket, aIp);
}
// Require auth for all other modules
if (!aRequest.getSession()) {
aRequest.setResponseErrorStr("Not authorized");
return websocketpp::http::status_code::unauthorized;
}
// Require using the same protocol that was used for logging in
if (aRequest.getSession()->isSecure() != aIsSecure) {
aRequest.setResponseErrorStr("Protocol mismatch");
return websocketpp::http::status_code::not_acceptable;
}
aRequest.getSession()->updateActivity();
code = aRequest.getSession()->handleRequest(aRequest);
} catch (const ArgumentException& e) {
aRequest.setResponseErrorJson(e.getErrorJson());
code = CODE_UNPROCESSABLE_ENTITY;
} catch (const std::exception& e) {
aRequest.setResponseErrorStr(e.what());
code = websocketpp::http::status_code::bad_request;
}
return static_cast<api_return>(code);
}