diff --git a/base/request.cc b/base/request.cc index 5377c55..cc62e5c 100644 --- a/base/request.cc +++ b/base/request.cc @@ -76,7 +76,8 @@ HTTPRequest::HTTPRequest(v8::Isolate* isolate, v8::Local conf) { v8::HandleScope handle_scope(isolate); auto tmp = config->Get(context, NewV8Key(isolate, "url")).FromMaybe(undefined); if (tmp->IsString()) { - SetUrl(*v8::String::Utf8Value(isolate, tmp)); + url = *v8::String::Utf8Value(isolate, tmp); + SetUrl(url); } } { @@ -220,6 +221,10 @@ HTTPResponse HTTPRequest::GetResponse() { } } +std::string HTTPRequest::GetUrl() const { + return this->url; +} + size_t AsyncRequest::pool_size = 1; size_t AsyncRequest::queue_cap = 1; @@ -229,10 +234,11 @@ bool AsyncRequest::Submit(std::shared_ptr request) { return pool->Post([request]() { auto response = request->GetResponse(); if (response.error) { - Platform::logger(std::string("async request failed: ") + response.error.message + std::string("\n")); + Platform::logger(std::string("async request failed; url: ") + request->GetUrl() + + ", errMsg: " + response.error.message + std::string("\n")); } else if (response.status_code != 200) { - Platform::logger(std::string("async request status: ") + std::to_string(response.status_code) + - std::string(" body: ") + response.text.substr(0, 1024) + std::string("\n")); + Platform::logger(std::string("async request status: ") + std::to_string(response.status_code) + ", url: " + + request->GetUrl() + ", body: " + response.text.substr(0, 1024) + std::string("\n")); } }); } diff --git a/base/request.h b/base/request.h index bc8dd26..12ed282 100644 --- a/base/request.h +++ b/base/request.h @@ -38,9 +38,11 @@ class HTTPRequest : public cpr::Session { HTTPRequest(v8::Isolate* isolate, v8::Local conf); void SetMethod(const std::string& method) { this->method = method; } HTTPResponse GetResponse(); + std::string GetUrl() const; private: std::string method; + std::string url; std::string error; }; diff --git a/base/tests/main.cc b/base/tests/main.cc index 3543972..4c100d9 100644 --- a/base/tests/main.cc +++ b/base/tests/main.cc @@ -730,8 +730,8 @@ TEST_CASE("AsyncRequest") { std::this_thread::sleep_for(std::chrono::milliseconds(100)); REQUIRE_THAT(message, Catch::Matchers::Contains( - "async request failed: Uncaught TypeError: Cannot convert undefined or null to object\n" - "async request failed: Uncaught TypeError: Cannot convert undefined or null to object\n")); + "async request failed; url: , errMsg: Uncaught TypeError: Cannot convert undefined or null to object\n" + "async request failed; url: , errMsg: Uncaught TypeError: Cannot convert undefined or null to object\n")); } SECTION("400", "[!mayfail]") {