diff --git a/src/MetaDataAPI/LambdaFunction.cs b/src/MetaDataAPI/LambdaFunction.cs index daeee90c..4d518db0 100644 --- a/src/MetaDataAPI/LambdaFunction.cs +++ b/src/MetaDataAPI/LambdaFunction.cs @@ -29,9 +29,15 @@ public LambdaResponse FunctionHandler(LambdaRequest request, ILambdaLogger logge { try { - if (request.ValidationResult != null) return new ValidationErrorResponse(request.ValidationResult); - - var chainInfo = chainManager.FetchChainInfo(request.ChainId); + if (request.ValidationResult != null) + { + return new ValidationErrorResponse(request.ValidationResult); + } + + if (!chainManager.TryFetchChainInfo(request.ChainId, out var chainInfo)) + { + return new ChainNotSupportedResponse(request.ChainId); + } var poolsInfo = AbstractProvider.FetchPoolInfo(request.PoolId, chainInfo); diff --git a/src/MetaDataAPI/Response/ChainNotSupportedResponse.cs b/src/MetaDataAPI/Response/ChainNotSupportedResponse.cs new file mode 100644 index 00000000..d45f4ba1 --- /dev/null +++ b/src/MetaDataAPI/Response/ChainNotSupportedResponse.cs @@ -0,0 +1,14 @@ +using System.Net; +using System.Numerics; + +namespace MetaDataAPI.Response; + +public class ChainNotSupportedResponse : LambdaResponse +{ + public ChainNotSupportedResponse(BigInteger chainId) + : base( + body: $"ChainID {chainId} is not supported.", + statusCode: HttpStatusCode.NotImplemented + ) + { } +} \ No newline at end of file diff --git a/src/MetaDataAPI/Services/ChainsInfo/IChainManager.cs b/src/MetaDataAPI/Services/ChainsInfo/IChainManager.cs index ad363145..8516ada4 100644 --- a/src/MetaDataAPI/Services/ChainsInfo/IChainManager.cs +++ b/src/MetaDataAPI/Services/ChainsInfo/IChainManager.cs @@ -1,8 +1,9 @@ using System.Numerics; +using System.Diagnostics.CodeAnalysis; namespace MetaDataAPI.Services.ChainsInfo; public interface IChainManager { - public ChainInfo FetchChainInfo(BigInteger chainId); + public bool TryFetchChainInfo(BigInteger chainId, [MaybeNullWhen(false)] out ChainInfo chainInfo); } \ No newline at end of file diff --git a/src/MetaDataAPI/Services/ChainsInfo/LocalChainManager.cs b/src/MetaDataAPI/Services/ChainsInfo/LocalChainManager.cs index 99e96329..54d720e5 100644 --- a/src/MetaDataAPI/Services/ChainsInfo/LocalChainManager.cs +++ b/src/MetaDataAPI/Services/ChainsInfo/LocalChainManager.cs @@ -1,4 +1,5 @@ using System.Numerics; +using System.Diagnostics.CodeAnalysis; namespace MetaDataAPI.Services.ChainsInfo; @@ -9,8 +10,8 @@ public class LocalChainManager : IChainManager { 97, new ChainInfo(97, "https://data-seed-prebsc-1-s1.binance.org:8545/", "0xe42876a77108E8B3B2af53907f5e533Cba2Ce7BE") } }; - public ChainInfo FetchChainInfo(BigInteger chainId) + public bool TryFetchChainInfo(BigInteger chainId, [MaybeNullWhen(false)] out ChainInfo chainInfo) { - return localChainInfo[chainId]; + return localChainInfo.TryGetValue(chainId, out chainInfo); } } \ No newline at end of file