diff --git a/lib/grpcServer/handlers/core/getBlockHandlerFactory.js b/lib/grpcServer/handlers/core/getBlockHandlerFactory.js index 089c815a0..5b3dc4367 100644 --- a/lib/grpcServer/handlers/core/getBlockHandlerFactory.js +++ b/lib/grpcServer/handlers/core/getBlockHandlerFactory.js @@ -6,6 +6,7 @@ const { server: { error: { InvalidArgumentGrpcError, + NotFoundGrpcError, }, }, } = require('@dashevo/grpc-common'); @@ -37,7 +38,7 @@ function getBlockHandlerFactory(insightAPI) { serializedBlock = await insightAPI.getRawBlockByHash(hash); } catch (e) { if (e.statusCode === 404) { - throw new InvalidArgumentGrpcError('Invalid block hash'); + throw new NotFoundGrpcError('Block not found'); } throw e; diff --git a/lib/grpcServer/handlers/core/getTransactionHandlerFactory.js b/lib/grpcServer/handlers/core/getTransactionHandlerFactory.js index 2c23a82b3..b6b772b20 100644 --- a/lib/grpcServer/handlers/core/getTransactionHandlerFactory.js +++ b/lib/grpcServer/handlers/core/getTransactionHandlerFactory.js @@ -8,6 +8,7 @@ const { server: { error: { InvalidArgumentGrpcError, + NotFoundGrpcError, }, }, } = require('@dashevo/grpc-common'); @@ -36,7 +37,7 @@ function getTransactionHandlerFactory(insightAPI) { serializedTransaction = await insightAPI.getRawTransactionById(id); } catch (e) { if (e.statusCode === 404) { - throw new InvalidArgumentGrpcError('Transaction not found'); + throw new NotFoundGrpcError('Transaction not found'); } throw e; diff --git a/lib/grpcServer/handlers/platform/getDataContractHandlerFactory.js b/lib/grpcServer/handlers/platform/getDataContractHandlerFactory.js index d9941dc36..3785ca601 100644 --- a/lib/grpcServer/handlers/platform/getDataContractHandlerFactory.js +++ b/lib/grpcServer/handlers/platform/getDataContractHandlerFactory.js @@ -2,6 +2,7 @@ const { server: { error: { InvalidArgumentGrpcError, + NotFoundGrpcError, }, }, } = require('@dashevo/grpc-common'); @@ -38,7 +39,7 @@ function getDataContractHandlerFactory(driveAPI, dpp) { dataContractJSON = await driveAPI.fetchContract(id); } catch (e) { if (e instanceof RPCError && e.code === -32602) { - throw new InvalidArgumentGrpcError(e.message, e.data); + throw new NotFoundGrpcError(e.message, e.data); } throw e; diff --git a/lib/grpcServer/handlers/platform/getIdentityHandlerFactory.js b/lib/grpcServer/handlers/platform/getIdentityHandlerFactory.js index 164dda88d..a1ab7eee7 100644 --- a/lib/grpcServer/handlers/platform/getIdentityHandlerFactory.js +++ b/lib/grpcServer/handlers/platform/getIdentityHandlerFactory.js @@ -2,6 +2,7 @@ const { server: { error: { InvalidArgumentGrpcError, + NotFoundGrpcError, }, }, } = require('@dashevo/grpc-common'); @@ -46,6 +47,9 @@ function getIdentityHandlerFactory(rpcClient, handleAbciResponse) { handleAbciResponse(result.response); const { response: { value: identityBase64 } } = result; + if (!identityBase64) { + throw new NotFoundGrpcError('Identity not found'); + } const response = new GetIdentityResponse(); diff --git a/test/unit/grpcServer/handlers/core/getBlockHandlerFactory.js b/test/unit/grpcServer/handlers/core/getBlockHandlerFactory.js index 5d3bc4f1c..6250f7cf9 100644 --- a/test/unit/grpcServer/handlers/core/getBlockHandlerFactory.js +++ b/test/unit/grpcServer/handlers/core/getBlockHandlerFactory.js @@ -2,6 +2,7 @@ const { server: { error: { InvalidArgumentGrpcError, + NotFoundGrpcError, }, }, } = require('@dashevo/grpc-common'); @@ -135,8 +136,8 @@ describe('getBlockHandlerFactory', () => { expect.fail('should thrown InvalidArgumentGrpcError error'); } catch (e) { - expect(e).to.be.instanceOf(InvalidArgumentGrpcError); - expect(e.getMessage()).to.equal('Invalid block hash'); + expect(e).to.be.instanceOf(NotFoundGrpcError); + expect(e.getMessage()).to.equal('Block not found'); expect(insightAPIMock.getRawBlockByHeight).to.be.not.called(); expect(insightAPIMock.getRawBlockByHash).to.be.calledOnceWith(hash); } diff --git a/test/unit/grpcServer/handlers/core/getTransactionHandlerFactory.js b/test/unit/grpcServer/handlers/core/getTransactionHandlerFactory.js index fde5a300e..167658ba2 100644 --- a/test/unit/grpcServer/handlers/core/getTransactionHandlerFactory.js +++ b/test/unit/grpcServer/handlers/core/getTransactionHandlerFactory.js @@ -2,6 +2,7 @@ const { server: { error: { InvalidArgumentGrpcError, + NotFoundGrpcError, }, }, } = require('@dashevo/grpc-common'); @@ -71,4 +72,20 @@ describe('getTransactionHandlerFactory', () => { expect(insightAPIMock.getRawTransactionById).to.be.not.called(); } }); + + it('should throw NotFoundGrpcError if transaction is not found', async () => { + const error = new Error(); + error.statusCode = 404; + insightAPIMock.getRawTransactionById.throws(error); + + try { + await getTransactionHandler(call); + + expect.fail('should thrown InvalidArgumentGrpcError error'); + } catch (e) { + expect(e).to.be.instanceOf(NotFoundGrpcError); + expect(e.getMessage()).to.equal('Transaction not found'); + expect(insightAPIMock.getRawTransactionById).to.be.calledOnceWith(id); + } + }); }); diff --git a/test/unit/grpcServer/handlers/platform/getDataContractHandlerFactory.js b/test/unit/grpcServer/handlers/platform/getDataContractHandlerFactory.js index 1fc8d7738..bd05f49ff 100644 --- a/test/unit/grpcServer/handlers/platform/getDataContractHandlerFactory.js +++ b/test/unit/grpcServer/handlers/platform/getDataContractHandlerFactory.js @@ -2,6 +2,7 @@ const { server: { error: { InvalidArgumentGrpcError, + NotFoundGrpcError, }, }, } = require('@dashevo/grpc-common'); @@ -99,7 +100,7 @@ describe('getDataContractHandlerFactory', () => { expect.fail('should throw InvalidArgumentGrpcError error'); } catch (e) { - expect(e).to.be.instanceOf(InvalidArgumentGrpcError); + expect(e).to.be.instanceOf(NotFoundGrpcError); expect(e.getMessage()).to.equal(message); expect(e.getMetadata()).to.deep.equal(data); expect(driveApiMock.fetchContract).to.be.calledOnceWith(id);