Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing catch of formatted json rpc error #118

Merged
merged 3 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/rollup-full-node/src/app/routing-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class RoutingHandler implements FullnodeHandler {
* @param method The Ethereum JSON RPC method.
* @param params The parameters.
* @param sourceIpAddress The requesting IP address.
* @throws FormattedJsonRpcError if the proxied response is a JsonRpcErrorResponse
*/
public async handleRequest(
method: string,
Expand Down Expand Up @@ -102,8 +103,9 @@ export class RoutingHandler implements FullnodeHandler {

this.assertDestinationValid(tx)

let result: JsonRpcResponse
try {
const result: JsonRpcResponse =
result =
methodsToRouteWithTransactionHandler.indexOf(method) >= 0
? await this.transactionClient.makeRpcCall(method, params)
: await this.readOnlyClient.makeRpcCall(method, params)
Expand All @@ -112,10 +114,6 @@ export class RoutingHandler implements FullnodeHandler {
params
)}] got result [${JSON.stringify(result)}]`
)
if (isJsonRpcErrorResponse(result)) {
throw new FormattedJsonRpcError(result as JsonRpcErrorResponse)
}
return result.result
} catch (e) {
logError(
log,
Expand All @@ -126,6 +124,11 @@ export class RoutingHandler implements FullnodeHandler {
)
throw e
}

if (isJsonRpcErrorResponse(result)) {
throw new FormattedJsonRpcError(result as JsonRpcErrorResponse)
}
return result.result
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup-full-node/test/app/routing-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe('Routing Handler', () => {
error.should.be.instanceOf(FormattedJsonRpcError, 'Invalid error type!')
const formatted: FormattedJsonRpcError = error as FormattedJsonRpcError
formatted.jsonRpcResponse.should.deep.equal(
transactionErrorResponsePayload,
transactionErrorRFesponsePayload,
'Incorrect error returned!'
)
})
Expand Down