Enabling disk_cache can lead to an exception (invalid_index) when changing channel
jynus opened this issue · comments
I did the following:
- Enabled disk_cache
- Connected and read some events from one Twitch channel
- Disconnected/closed my application
- Connected to a different channel
I got the following error:
Invalid get index 'badge_sets' (on base 'Dictionary').
(gift_node.gd:525)
I guessed that it assumes that if the cache exists, it contains this key. I fixed the issue by changing the logic to this:
if (disk_cache && FileAccess.file_exists(filename)):
var cache = JSON.parse_string(FileAccess.get_file_as_string(filename))
if "badge_sets" in cache:
return cache["badge_sets"]
var request : HTTPRequest = HTTPRequest.new()
add_child(request)
request.request("https://api.twitch.tv/helix/chat/badges" + ("/global" if channel_id == "_global" else "?broadcaster_id=" + channel_id), [USER_AGENT, "Authorization: Bearer " + token["access_token"], "Client-Id:" + client_id, "Content-Type: application/json"], HTTPClient.METHOD_GET)
Let me know what you think and I can send you a PR, if it seems like a reasonable change.
Hey, sorry for the late response - the change looks good to me, feel free to create a PR ^^
Will do.
There you have it- I chose to short circuit the 3 main blocks, as I thought it was clearer in this case than the "single return at the end". I tested it by connecting and reconnecting to several channels and deleting the cache files several times, but further testing will be welcome, too! :-D
Thank you a lot!