EDTS: fixed “bad request” error handling on invalid system names

This commit is contained in:
alterNERDtive 2022-02-15 17:26:58 +01:00
parent e6b29874c3
commit 6f8144a7be

View file

@ -75,24 +75,13 @@ namespace alterNERDtive.Edna.Edts
/// <returns>The system with calculated coordinates.</returns>
public static async Task<StarSystem> FindSystem(string name)
{
try
RestResponse<ApiResult> response = await ApiClient.ExecuteAsync<ApiResult>(new RestRequest($"system_position/{name}"));
if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
ApiResult result = await ApiClient.GetAsync<ApiResult>(new RestRequest($"system_position/{name}"));
return result.Result!.Value;
}
catch (HttpRequestException e)
{
// EDTS API gives a 400 status code (and an empty result) if the
// system name is not valid.
if (e.Message.Equals("Request failed with status code BadRequest"))
{
throw new ArgumentException(message: $"“{name}” is not a valid proc gen system name.", paramName: nameof(name));
}
else
{
throw;
}
throw new ArgumentException(message: $"“{name}” is not a valid proc gen system name.", paramName: nameof(name));
}
return response.Data.Result!.Value;
}
private struct ApiResult