Skip to content

Commit

Permalink
Log in a proper way
Browse files Browse the repository at this point in the history
  • Loading branch information
negrifelipe committed Dec 24, 2021
1 parent 16a955a commit 843a58d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Feli.OpenMod.JoinLeaveMessages/Helpers/IpGeolocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ public IpGeolocationHelper(ILogger<IpGeolocationHelper> logger)

public async Task<string> GetCountryFromIpAsync(string address)
{
var respnse = await _client.GetAsync($"http://ip-api.com/json/{address}?fields=status,message,country");
var response = await _client.GetAsync($"http://ip-api.com/json/{address}?fields=status,message,country");

if (!respnse.IsSuccessStatusCode)
if (!response.IsSuccessStatusCode)
{
_logger.LogError($"HTTP Error: {(int)respnse.StatusCode}, {respnse.StatusCode}");
_logger.LogError("HTTP Error: {StatusCode}, {StatusCodeString}", (int)response.StatusCode, response.StatusCode.ToString());
return string.Empty;
}

var content = await respnse.Content.ReadAsStringAsync();
var content = await response.Content.ReadAsStringAsync();

var @object = JObject.Parse(content);

if (@object["status"].ToString() == "fail")
{
_logger.LogError($"Failed to get the ip location. Error: {@object["message"]}");
_logger.LogError("Failed to get the ip location. Error: {message}", @object["message"].ToString());
return string.Empty;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public static string GetCountryFromIp(string address)
{
var client = new HttpClient();

var respnse = client.GetAsync($"http://ip-api.com/json/{address}?fields=status,message,country").GetAwaiter().GetResult();
var response = client.GetAsync($"http://ip-api.com/json/{address}?fields=status,message,country").GetAwaiter().GetResult();

if (!respnse.IsSuccessStatusCode)
if (!response.IsSuccessStatusCode)
{
Logger.LogError($"HTTP Error: {(int)respnse.StatusCode}, {respnse.StatusCode}");
Logger.LogError($"HTTP Error: {(int)response.StatusCode}, {response.StatusCode}");
return string.Empty;
}

var content = respnse.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();

var @object = JObject.Parse(content);

Expand Down

0 comments on commit 843a58d

Please sign in to comment.