From b5e841a0684ad77c372fe2dea5a6a3bb115c522b Mon Sep 17 00:00:00 2001 From: svr333 Date: Thu, 14 Jan 2021 22:57:37 +0100 Subject: [PATCH] Improve enduser usage --- src/Exceptions/ServersNotOnlineException.cs | 7 +++++++ src/Exceptions/StatsNotFoundException.cs | 8 ++++---- src/GLR.Net.csproj | 2 +- src/GLRClientAsync.cs | 7 ++++++- 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/Exceptions/ServersNotOnlineException.cs diff --git a/src/Exceptions/ServersNotOnlineException.cs b/src/Exceptions/ServersNotOnlineException.cs new file mode 100644 index 0000000..c3e4d12 --- /dev/null +++ b/src/Exceptions/ServersNotOnlineException.cs @@ -0,0 +1,7 @@ +namespace GLR.Net.Exceptions +{ + public class ServersLaunchingException : GLRException + { + public override string Message => $"Servers are still launching!"; + } +} diff --git a/src/Exceptions/StatsNotFoundException.cs b/src/Exceptions/StatsNotFoundException.cs index e80906c..723bfe3 100644 --- a/src/Exceptions/StatsNotFoundException.cs +++ b/src/Exceptions/StatsNotFoundException.cs @@ -5,12 +5,12 @@ namespace GLR.Net.Exceptions { public class StatsNotFoundException : Exception { - public StatsNotFoundException(BasicProfile user) + public StatsNotFoundException(string id) { - User = user; + UserId = id; } - public BasicProfile User { get; set; } - public override string Message => $"User statistics for '{User.Username}' not found."; + public string UserId { get; set; } + public override string Message => $"User statistics for '{UserId}' not found."; } } diff --git a/src/GLR.Net.csproj b/src/GLR.Net.csproj index 15cace2..4c0f772 100644 --- a/src/GLR.Net.csproj +++ b/src/GLR.Net.csproj @@ -1,7 +1,7 @@ netstandard2.0 - 2.8 + 2.9 svr333 Galaxy Life Reborn GLR.Net diff --git a/src/GLRClientAsync.cs b/src/GLRClientAsync.cs index 4f8fba5..aa95bf5 100644 --- a/src/GLRClientAsync.cs +++ b/src/GLRClientAsync.cs @@ -10,7 +10,7 @@ namespace GLR.Net { public partial class GLRClient { - private HttpClient _webClient = new HttpClient() { Timeout = TimeSpan.FromMilliseconds(500) }; + private HttpClient _webClient = new HttpClient() { Timeout = TimeSpan.FromSeconds(1000) }; public async Task GetUserAsync(string input) { @@ -39,6 +39,11 @@ public async Task GetStatisticsAsync(string id) var response = await _webClient.GetAsync($"https://mariflash.galaxylifereborn.com/account/statistics?id={id}"); var statisticsJson = await response.Content.ReadAsStringAsync(); + if (statisticsJson == "Not ready!") + throw new ServersLaunchingException(); + else if (statisticsJson == "Error!") + throw new StatsNotFoundException(id); + return JsonConvert.DeserializeObject(statisticsJson); }