Skip to content

Commit

Permalink
serialize errors using eth-json-rpc-errors; add .nvmrc (#14)
Browse files Browse the repository at this point in the history
* serialize errors using eth-json-rpc-errors
* add .nvmrc
* remove dead code
  • Loading branch information
rekmarks authored and danfinlay committed Aug 9, 2019
1 parent f8186c7 commit 5f86d20
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
46 changes: 35 additions & 11 deletions merged-packages/json-rpc-engine/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions merged-packages/json-rpc-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@babel/preset-env": "^7.3.4",
"async": "^2.0.1",
"babelify": "^10.0.0",
"eth-json-rpc-errors": "^0.3.1",
"promise-to-callback": "^1.0.0",
"safe-event-emitter": "^1.0.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const promiseToCallback = require('promise-to-callback')

module.exports = createAsyncMiddleware


function createAsyncMiddleware(asyncMiddleware) {
return (req, res, next, end) => {
let nextDonePromise = null
Expand Down
12 changes: 5 additions & 7 deletions merged-packages/json-rpc-engine/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

import { IJsonRpcError } from 'eth-json-rpc-errors'

/** A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0". */
export type JsonRpcVersion = "2.0";

Expand All @@ -12,6 +15,8 @@ export type JsonRpcReservedMethod = string;
* NOT contain fractional parts [2] */
export type JsonRpcId = number | string | void;

interface JsonRpcError<T> extends IJsonRpcError<T> {}

interface JsonRpcRequest<T> {
jsonrpc: JsonRpcVersion;
method: string;
Expand Down Expand Up @@ -39,13 +44,6 @@ interface JsonRpcFailure<T> extends JsonRpcResponse<T> {
error: JsonRpcError<T>;
}

interface JsonRpcError<T> {
/** Must be an integer */
code: number;
message: string;
data?: T;
}

type JsonRpcEngineEndCallback = (error?: JsonRpcError<any>) => void;
type JsonRpcEngineNextCallback = (returnFlightCallback?: (done: () => void) => void) => void;

Expand Down
12 changes: 1 addition & 11 deletions merged-packages/json-rpc-engine/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
const async = require('async')
const SafeEventEmitter = require('safe-event-emitter')
const { serializeError } = require('eth-json-rpc-errors')

class RpcEngine extends SafeEventEmitter {
constructor () {
Expand Down Expand Up @@ -76,10 +77,6 @@ class RpcEngine extends SafeEventEmitter {
// continue
return cb(null, returnHandlers)
}

function runReturnHandlers (returnHandlers, cb) {
async.eachSeries(returnHandlers, (handler, next) => handler(next), onDone)
}
}

// walks down stack of middleware
Expand Down Expand Up @@ -136,11 +133,4 @@ class RpcEngine extends SafeEventEmitter {
}
}

function serializeError(err) {
return {
code: err.code || -32603,
message: err.stack,
}
}

module.exports = RpcEngine

0 comments on commit 5f86d20

Please sign in to comment.