Problem: The rawgAPI was only set when the plugin initially loaded. A user could enter their API key on the settings page, but the plugin wouldn't start using the API key until the plugin was reloaded (e.g., when the user closed and re-opened Obsidian). I believe this to be the most likely cause of the 401 errors that would seemingly resolve in time.
Solution: Added a line to the saveSettings() function that re-initializes the API, thus immediately picking up on changes to the API key.
Testing:
Original
Successfully searched for a game with a working API key (to ensure everything was working to begin with)
Changed the API key to something obviously invalid (e.g., 5555555)
Searched for a different game
The search still worked because the API wasn't re-initialized and was still using the valid key
Modified Version
Successfully searched for a game with a working API key (to ensure everything was working to begin with)
Changed the API key to something obviously invalid (e.g., 5555555)
Searched for a different game
The search failed with a 401 error because the API key was invalid
Refreshed my RAWR API key
Configured Game Search to use the new API key
Searched for a game
The search completed successfully (less than a minute after refreshing the key)
Problem: The
rawgAPI
was only set when the plugin initially loaded. A user could enter their API key on the settings page, but the plugin wouldn't start using the API key until the plugin was reloaded (e.g., when the user closed and re-opened Obsidian). I believe this to be the most likely cause of the 401 errors that would seemingly resolve in time.Solution: Added a line to the
saveSettings()
function that re-initializes the API, thus immediately picking up on changes to the API key.Testing:
5555555
)5555555
)401
error because the API key was invalid