Foxlider / FASTER

Full rebuild of Flax's tool for installing and updating Arma 3 server with built in features for managing Steam Workshop mods.
GNU General Public License v3.0
123 stars 34 forks source link

[BUG] Bad API key silently fails, Causes mod info to be blank #167

Open AgentDove opened 6 months ago

AgentDove commented 6 months ago

Describe the bug
A bad API key will cause the API call to return a 401 response, and does not catch it. This returns null to the ArmaMod.UpdateInfos loop and fails for each of it's tries, and has no check for all attempts failing. ArmaModCollection.AddSteamMod adds the new mod before getting info on it, and doesn't do anything if info getting fails.

To Reproduce

  1. Use a bad or expired API key. (through setup or by editing the config)
  2. Add a new mod or mods through the mods page.
  3. The new mod/mods will have no name or author and a size of 0.00B.

Expected behaviour
A mods info should be filled out. If that is not possible it should raise an error, with the response type. And depending if it's a 401, prompt to update or remove the API key.

Actual behaviour
The fields of a mods info will be null; Name, Author, SteamLastUpdated, LocalLastUpdated, Size.

Screenshots
image

OS Version:

Additional context

Newtonsoft.Json.JsonReaderException
  HResult=0x80131500
  Message=Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
  Source=Newtonsoft.Json
  StackTrace:
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
   at FASTER.Models.SteamWebApi.ApiCall(String uri) in C:\Users\Administrator\source\repos\FASTER\FASTER\Models\SteamWebApi.cs:line 87
   at FASTER.Models.SteamWebApi.GetSingleFileDetails(UInt32 modId) in C:\Users\Administrator\source\repos\FASTER\FASTER\Models\SteamWebApi.cs:line 29

  This exception was originally thrown at this call stack:
    [External Code]
    FASTER.Models.SteamWebApi.ApiCall(string) in SteamWebApi.cs
    FASTER.Models.SteamWebApi.GetSingleFileDetails(uint) in SteamWebApi.cs

// Bad API key
{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: nginx
  Cache-Control: max-age=0, no-cache, no-store
  Pragma: no-cache
  Date: Sat, 17 Feb 2024 19:52:32 GMT
  Connection: keep-alive
  Content-Type: text/html; charset=UTF-8
  Content-Length: 174
  Expires: Sat, 17 Feb 2024 19:52:32 GMT
}}

// No API key
{StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: nginx
  X-eresult: 1
  Date: Sat, 17 Feb 2024 20:01:19 GMT
  Connection: keep-alive
  Content-Type: application/json; charset=UTF-8
  Expires: Sat, 17 Feb 2024 20:01:19 GMT
  Content-Length: 2287
}}
OverlordZorn commented 6 months ago

grafik