From caf6d7a7ad05bd814e022423a0b48c8dafdf15ce Mon Sep 17 00:00:00 2001 From: dragonflylee Date: Thu, 4 Jul 2024 18:32:37 +0800 Subject: [PATCH] Show more info for http error --- wiliwili/include/api/bilibili/util/http.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wiliwili/include/api/bilibili/util/http.hpp b/wiliwili/include/api/bilibili/util/http.hpp index dab85803..5942faa9 100644 --- a/wiliwili/include/api/bilibili/util/http.hpp +++ b/wiliwili/include/api/bilibili/util/http.hpp @@ -48,8 +48,8 @@ class HTTP { const ErrorCallback& error = nullptr) { cpr::PostCallback( [callback, error](const cpr::Response& r) { - if (r.status_code == 0) { - ERROR_MSG("No network connection", -1); + if (r.error) { + ERROR_MSG(r.error.message, -1); return; } else if (r.status_code != 200) { ERROR_MSG("Network error. [Status code: " + std::to_string(r.status_code) + " ]", r.status_code); @@ -66,8 +66,8 @@ class HTTP { const ErrorCallback& error = nullptr) { cpr::GetCallback( [callback, error](const cpr::Response& r) { - if (r.status_code == 0) { - ERROR_MSG("No network connection", -1); + if (r.error) { + ERROR_MSG(r.error.message, -1); return; } else if (r.status_code != 200) { ERROR_MSG("Network error. [Status code: " + std::to_string(r.status_code) + " ]", r.status_code); @@ -116,10 +116,10 @@ class HTTP { ERROR_MSG("Param error", -1); } } catch (const std::exception& e) { - if (r.status_code == 200) { + if (r.error) { + ERROR_MSG(r.error.message, -1); + } else if (r.status_code == 200) { ERROR_MSG("Api error. \n" + std::string{e.what()}, 200); - } else if (r.status_code == 0) { - ERROR_MSG("No network connection", -1); } else { ERROR_MSG("Network error. \nStatus code: " + std::to_string(r.status_code), r.status_code); }