mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 15:26:59 +00:00
Sentry: sort by response code
This commit is contained in:
parent
683e13a4a0
commit
4b92532203
@ -61,12 +61,14 @@ inline void _assert([[maybe_unused]] const char* file, [[maybe_unused]] const ch
|
||||
// In release build, these macros turn into NOPs. The compiler will optimize these out.
|
||||
#define Assert(cond) \
|
||||
do { \
|
||||
bool result = (cond); \
|
||||
if (!result) { \
|
||||
Sentry.LogAssert(#cond, _file_basename, _line, __func__); \
|
||||
} \
|
||||
} while (false)
|
||||
#define AssertNotReachable() \
|
||||
do { \
|
||||
bool result = (cond); \
|
||||
if (!result) { \
|
||||
Sentry.LogAssert("code is unreachable", _file_basename, _line, __func__); \
|
||||
} \
|
||||
|
@ -5,5 +5,5 @@
|
||||
|
||||
namespace Http {
|
||||
std::string GET(const std::string& host, int port, const std::string& target);
|
||||
std::string POST(const std::string& host, const std::string& target, const std::unordered_map<std::string, std::string>& fields, const std::string& body, bool json);
|
||||
}
|
||||
std::string POST(const std::string& host, const std::string& target, const std::unordered_map<std::string, std::string>& fields, const std::string& body, bool json, int* status = nullptr);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ std::string Http::GET(const std::string& host, int port, const std::string& targ
|
||||
}
|
||||
}
|
||||
|
||||
std::string Http::POST(const std::string& host, const std::string& target, const std::unordered_map<std::string, std::string>& fields, const std::string& body, bool json) {
|
||||
std::string Http::POST(const std::string& host, const std::string& target, const std::unordered_map<std::string, std::string>& fields, const std::string& body, bool json, int* status) {
|
||||
try {
|
||||
net::io_context io;
|
||||
|
||||
@ -136,6 +136,9 @@ std::string Http::POST(const std::string& host, const std::string& target, const
|
||||
|
||||
std::unordered_map<std::string, std::string> response_data;
|
||||
response_data["reponse-code"] = std::to_string(response.result_int());
|
||||
if (status) {
|
||||
*status = response.result_int();
|
||||
}
|
||||
for (const auto& header : response.base()) {
|
||||
// need to do explicit casts to convert string_view to string
|
||||
// since string_view may not be null-terminated (and in fact isn't, here)
|
||||
|
@ -36,7 +36,8 @@ void THeartbeatThread::operator()() {
|
||||
Body += "&pps=" + Application::PPS();
|
||||
|
||||
auto Target = "/heartbeat";
|
||||
T = Http::POST(Application::GetBackendHostname(), Target, {}, Body, false);
|
||||
int ResponseCode = -1;
|
||||
T = Http::POST(Application::GetBackendHostname(), Target, {}, Body, false, &ResponseCode);
|
||||
|
||||
if (T.substr(0, 2) != "20") {
|
||||
auto SentryReportError = [&](const std::string& transaction) {
|
||||
@ -47,7 +48,7 @@ void THeartbeatThread::operator()() {
|
||||
{ { "response-body", T },
|
||||
{ "request-body", Body } });
|
||||
Sentry.SetTransaction(transaction);
|
||||
Sentry.Log(SENTRY_LEVEL_ERROR, "default", "wrong backend response format");
|
||||
Sentry.Log(SENTRY_LEVEL_ERROR, "default", "wrong backend response format (" + std::to_string(ResponseCode) + ")");
|
||||
}
|
||||
};
|
||||
SentryReportError(Application::GetBackendHostname() + Target);
|
||||
|
@ -283,8 +283,9 @@ void TNetwork::Authentication(SOCKET TCPSock) {
|
||||
auto RequestString = R"({"key":")" + Rc + "\"}";
|
||||
|
||||
auto Target = "/pkToUser";
|
||||
int ResponseCode = -1;
|
||||
if (!Rc.empty()) {
|
||||
Rc = Http::POST(Application::GetBackendUrlForAuth(), Target, {}, RequestString, true);
|
||||
Rc = Http::POST(Application::GetBackendUrlForAuth(), Target, {}, RequestString, true, &ResponseCode);
|
||||
}
|
||||
|
||||
json::Document AuthResponse;
|
||||
@ -302,7 +303,7 @@ void TNetwork::Authentication(SOCKET TCPSock) {
|
||||
{ { "response-body", Rc },
|
||||
{ "key", RequestString } });
|
||||
Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target);
|
||||
Sentry.Log(SENTRY_LEVEL_ERROR, "default", "auth: wrong backend response format");
|
||||
Sentry.Log(SENTRY_LEVEL_ERROR, "default", "wrong backend response format (" + std::to_string(ResponseCode) + ")");
|
||||
return;
|
||||
} else if (Rc == "0") {
|
||||
auto Lock = Sentry.CreateExclusiveContext();
|
||||
@ -310,7 +311,7 @@ void TNetwork::Authentication(SOCKET TCPSock) {
|
||||
{ { "response-body", Rc },
|
||||
{ "key", RequestString } });
|
||||
Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target);
|
||||
Sentry.Log(SENTRY_LEVEL_INFO, "default", "backend returned 0 instead of json");
|
||||
Sentry.Log(SENTRY_LEVEL_INFO, "default", "backend returned 0 instead of json (" + std::to_string(ResponseCode) + ")");
|
||||
}
|
||||
|
||||
if (AuthResponse["username"].IsString() && AuthResponse["roles"].IsString()
|
||||
|
Loading…
x
Reference in New Issue
Block a user