Skip to content

Commit

Permalink
Added error message if user tries to add non-existing satellite
Browse files Browse the repository at this point in the history
  • Loading branch information
JKamue committed Nov 28, 2020
1 parent a442f87 commit 3bc35b6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions SatWatcher/Data/TLEApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ public static Result<Satellite> GetSatellite(long id)
}

var tleResponse = JObject.Parse(response);
var results = tleResponse["member"]?.Children().ToList().First();
var results = tleResponse["member"]?.Children().ToList();

if (results?.Count != 1)
{
return Result.Failure<Satellite>($"{results.Count} satellites with this number were found");
}

var result = results.First();
return new Satellite(
GetValue<long>(results, "satelliteId"),
GetValue<string>(results, "name"),
GetValue<string>(results, "line1"),
GetValue<string>(results, "line2")
GetValue<long>(result, "satelliteId"),
GetValue<string>(result, "name"),
GetValue<string>(result, "line1"),
GetValue<string>(result, "line2")
);
}

Expand Down

0 comments on commit 3bc35b6

Please sign in to comment.