Compare commits

...

1 Commits

Author SHA1 Message Date
Ian Chua
3ad2f82ff9 fix: set a grace period for 401 api calls 2026-05-21 20:12:08 +08:00
2 changed files with 19 additions and 9 deletions

View File

@@ -4846,18 +4846,23 @@ void GUI_App::on_http_error(wxCommandEvent &evt)
if (status == 401) { if (status == 401) {
if (m_agent) { if (m_agent) {
if (m_agent->is_user_login(provider)) { if (m_agent->is_user_login(provider)) {
BOOST_LOG_TRIVIAL(warning) << "logout: http error 401."; if (std::chrono::steady_clock::now() - m_last_401_error_time > 30s) {
this->request_user_logout(provider); BOOST_LOG_TRIVIAL(warning) << "logout: http error 401.";
this->request_user_logout(provider);
if (!m_show_http_error_msgdlg) { if (!m_show_http_error_msgdlg) {
MessageDialog msg_dlg(nullptr, _L("Login information expired. Please login again."), "", wxAPPLY | wxOK); MessageDialog msg_dlg(nullptr, _L("Login information expired. Please login again."), "", wxAPPLY | wxOK);
m_show_http_error_msgdlg = true; m_show_http_error_msgdlg = true;
auto modal_result = msg_dlg.ShowModal(); auto modal_result = msg_dlg.ShowModal();
if (modal_result == wxOK || modal_result == wxCLOSE) { if (modal_result == wxOK || modal_result == wxCLOSE) {
m_show_http_error_msgdlg = false; m_show_http_error_msgdlg = false;
return; return;
}
} }
} else {
BOOST_LOG_TRIVIAL(warning) << "401 encountered within grace period, suppressing logout";
} }
m_last_401_error_time = std::chrono::steady_clock::now();
} }
} }
return; return;
@@ -4931,6 +4936,10 @@ void GUI_App::on_user_login_handle(wxCommandEvent &evt)
std::string provider = evt.GetString().ToStdString(); std::string provider = evt.GetString().ToStdString();
if (provider.empty()) provider = ORCA_CLOUD_PROVIDER; if (provider.empty()) provider = ORCA_CLOUD_PROVIDER;
// Reset 401 grace period so transient token-propagation 401s
// during login warmup don't trigger immediate logout.
m_last_401_error_time = std::chrono::steady_clock::now();
m_agent->connect_server(); m_agent->connect_server();
// get machine list // get machine list
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();

View File

@@ -326,6 +326,7 @@ private:
bool m_adding_script_handler { false }; bool m_adding_script_handler { false };
bool m_side_popup_status{false}; bool m_side_popup_status{false};
bool m_show_http_error_msgdlg{false}; bool m_show_http_error_msgdlg{false};
std::chrono::steady_clock::time_point m_last_401_error_time;
bool m_show_error_msgdlg{false}; bool m_show_error_msgdlg{false};
wxString m_info_dialog_content; wxString m_info_dialog_content;
HttpServer m_http_server; HttpServer m_http_server;