Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Bugfix: Fixed crashes that could occur when Lua functions errored with values other than strings. (#6441)
- Bugfix: Fixed zero-width global BTTV emotes not showing in the `:~` completions. (#6440)
- Bugfix: Fixed an issue where the update button would be unclickable on macOS and Linux. (#6447)
- Bugfix: Fixed Lua errors from handlers of HTTP requests not being logged. (#6452)

## 2.5.4-beta.1

Expand Down
17 changes: 9 additions & 8 deletions src/controllers/plugins/api/HTTPRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ void HTTPRequest::execute(sol::this_state L)
auto hack = this->weak_from_this();
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
pl->httpRequests.push_back(this->shared_from_this());
auto *mainState = pl->state().lua_state();

std::move(this->req_)
.onSuccess([hack](const NetworkResult &res) {
.onSuccess([pl, hack](const NetworkResult &res) {
auto self = hack.lock();
if (!self)
{
Expand All @@ -128,10 +127,12 @@ void HTTPRequest::execute(sol::this_state L)
{
return;
}
(*self->cbSuccess)(HTTPResponse(res));

loggedVoidCall(*self->cbSuccess, u"HTTPRequest::on_success", pl,
HTTPResponse(res));
self->cbSuccess = std::nullopt;
})
.onError([hack](const NetworkResult &res) {
.onError([pl, hack](const NetworkResult &res) {
auto self = hack.lock();
if (!self)
{
Expand All @@ -141,17 +142,17 @@ void HTTPRequest::execute(sol::this_state L)
{
return;
}
(*self->cbError)(HTTPResponse(res));
loggedVoidCall(*self->cbError, u"HTTPRequest::on_error", pl,
HTTPResponse(res));
self->cbError = std::nullopt;
})
.finally([mainState, hack]() {
.finally([pl, hack]() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we can just pass the plugin pointer here, because the plugin owns hack (see line 117).

I think, in the future, we could have some more generic plugin handle that we could store here (the plugin shouldn't need to know that HTTP requests exist). We can't put the plugin in a std::shared_ptr itself, but we could make the plugin own some shared pointer. That's for the next release, though.

auto self = hack.lock();
if (!self)
{
// this could happen if the plugin was deleted
return;
}
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(mainState);
for (auto it = pl->httpRequests.begin();
it < pl->httpRequests.end(); it++)
{
Expand All @@ -166,7 +167,7 @@ void HTTPRequest::execute(sol::this_state L)
{
return;
}
(*self->cbFinally)();
loggedVoidCall(*self->cbFinally, u"HTTPRequest::finally", pl);
self->cbFinally = std::nullopt;
})
.timeout(this->timeout_)
Expand Down
Loading