Skip to content

Commit

Permalink
feat: Handle redis, resapi timeout (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atralupus authored Dec 28, 2023
1 parent 0f08688 commit e4006b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 10 additions & 5 deletions NineChronicles.Headless/Services/RedisAccessControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ public RedisAccessControlService(string storageUri)

public int? GetTxQuota(Address address)
{
RedisValue result = _db.StringGet(address.ToString());
if (!result.IsNull)
try
{
return Convert.ToInt32(result);
}
RedisValue result = _db.StringGet(address.ToString());

return null;
return !result.IsNull ? Convert.ToInt32(result) : null;
}
catch (RedisTimeoutException)
{
Log.ForContext("Source", nameof(IAccessControlService))
.Error("\"{Address}\" Redis timeout.", address);
return null;
}
}
}
}
11 changes: 9 additions & 2 deletions NineChronicles.Headless/Services/RestAPIAccessControlService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using System.Net.Http;
using Libplanet.Crypto;
using Nekoyume.Blockchain;
Expand Down Expand Up @@ -33,9 +34,15 @@ public RestAPIAccessControlService(string baseUrl)
return Convert.ToInt32(resultString);
}
}
catch (Exception ex)
catch (TaskCanceledException)
{
Log.Error(ex, "Error occurred while calling Rest API.");
Log.ForContext("Source", nameof(IAccessControlService))
.Error("RestAPI timeout for \"{Address}\".", address);
}
catch (HttpRequestException ex)
{
Log.ForContext("Source", nameof(IAccessControlService))
.Error(ex, "HttpRequestException occurred for \"{Address}\".", address);
}

return null;
Expand Down

0 comments on commit e4006b3

Please sign in to comment.