Skip to content

Commit

Permalink
feat: add exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mixhsnhd committed Dec 26, 2024
1 parent 2abedac commit 8125180
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Threading.Tasks;
using AElf.ExceptionHandler;
using EoaServer.Commons;
using EoaServer.Options;
using EoaServer.Token;
Expand All @@ -7,8 +9,10 @@
using EoaServer.UserAssets;
using EoaServer.UserAssets.Dtos;
using EoaServer.UserAssets.Provider;
using Google.Protobuf.WellKnownTypes;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Orleans.Providers;
using Volo.Abp.Application.Dtos;
using Volo.Abp.DependencyInjection;

Expand Down Expand Up @@ -56,6 +60,7 @@ public async Task<GetAddressNftListResultDto> GetAddressNftListAsync(string chai
return chainTokenList;
}

[ExceptionHandler(typeof(Exception), Message = "GetTransactionDetailAsync Error", LogOnly = true)]
public async Task<TransactionDetailResponseDto> GetTransactionDetailAsync(string chainId, string transactionId)
{
var url = _aelfScanOptions.BaseUrl + "/" + CommonConstant.AelfScanTransactionDetailApi;
Expand Down
11 changes: 7 additions & 4 deletions src/EoaServer.Application/Common/Provider/HttpClientProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -41,14 +42,16 @@ public async Task<T> GetAsync<T>(string url, Dictionary<string, string> headers)
var response = await client.GetStringAsync(url);
return JsonConvert.DeserializeObject<T>(response);
}
public async Task<T> GetDataAsync<T>(string url)

public async Task<T> GetDataAsync<T>(string url, int timeout = 1000)
{
var response = await _httpClientFactory.CreateClient().GetStringAsync(url);
var client = _httpClientFactory.CreateClient();
client.Timeout = new TimeSpan(0, 0, 0, 0, timeout);
var response = await client.GetStringAsync(url);
var json = JObject.Parse(response);
return json["data"].ToObject<T>();
}

public async Task<T> GetAsync<T>(string url, IDictionary<string, string> headers)
{
if (headers == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IHttpClientProvider
{
Task<T> GetAsync<T>(string url);
Task<T> GetAsync<T>(string url, Dictionary<string, string> headers);
Task<T> GetDataAsync<T>(string url);
Task<T> GetDataAsync<T>(string url, int timeout = 1000);
Task<T> PostAsync<T>(string url);
Task<T> PostAsync<T>(string url, object paramObj);
Task<T> PostAsync<T>(string url, object paramObj, Dictionary<string, string> headers);
Expand Down
1 change: 1 addition & 0 deletions src/EoaServer.Application/EoaServer.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="RestSharp" Version="111.2.0" />
<PackageReference Include="AElf.ExceptionHandler.ABP" Version="8.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public async Task<GetActivitiesDto> GetActivitiesAsync(GetActivitiesRequestDto r
}
txnChainMap[txn.TransactionId] = txn.ChainIds[0];
var txnDetail = await _aelfScanDataProvider.GetTransactionDetailAsync(txn.ChainIds[0], txn.TransactionId);
if (txnDetail == null)
{
_logger.LogError($"Get transaction detail error. ChainId: {txn.ChainIds[0]}, TransactionId: {txn.TransactionId}");
}
return txnDetail;
}).ToList();

Expand Down
4 changes: 2 additions & 2 deletions src/EoaServer.HttpApi.Host/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"Configuration": "127.0.0.1"
},
"AuthServer": {
"Authority": "http://127.0.0.1:8080",
"Authority": "https://auth-aa-portkey-test.portkey.finance",
"RequireHttpsMetadata": "false",
"SwaggerClientId": "EoaServer_App"
"SwaggerClientId": "CAServer_App"
},
"StringEncryption": {
"DefaultPassPhrase": "gaMgs0gtsqpYZUTn"
Expand Down
2 changes: 1 addition & 1 deletion src/EoaServer.Silo/appsettings.apollo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"Timeout": 5000,
"StartupTimeout": 30000
},
"IsApolloEnabled": true
"IsApolloEnabled": false
}
2 changes: 1 addition & 1 deletion src/EoaServer.Silo/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Orleans": {
"IsRunningInKubernetes": true,
"IsRunningInKubernetes": false,
"ClusterId": "EoaServerSiloCluster",
"ServiceId": "EoaServerOrleansBasicService",
"AdvertisedIP": "127.0.0.1",
Expand Down

0 comments on commit 8125180

Please sign in to comment.