diff --git a/jsonrpc/scripts/build.js b/jsonrpc/scripts/build.js index 6f17c8c1..3677f8da 100644 --- a/jsonrpc/scripts/build.js +++ b/jsonrpc/scripts/build.js @@ -43,6 +43,19 @@ contentFiles.forEach(file => { }; }); +let errors = {}; +let errorBase = "src/errors/" +let errorFiles = fs.readdirSync(errorBase) +errorFiles.forEach(file => { + console.log(file); + let raw = fs.readFileSync(errorBase + file); + let parsed = JSON.parse(raw); + errors = { + ...errors, + ...parsed, + }; +}); + let spec = await parseOpenRPCDocument({ openrpc: "1.2.4", info: { @@ -57,7 +70,8 @@ let spec = await parseOpenRPCDocument({ methods: methods, components: { contentDescriptors: content, - schemas: schemas + schemas: schemas, + errors: errors } }, {dereference: false}) diff --git a/jsonrpc/scripts/debug.sh b/jsonrpc/scripts/debug.sh index 7e4d76b6..7cdd5387 100755 --- a/jsonrpc/scripts/debug.sh +++ b/jsonrpc/scripts/debug.sh @@ -2,6 +2,6 @@ set -o xtrace curl -s http://localhost:8545 -H 'Content-Type: application/json' -d '{"method":"'$1'","id":1,"jsonrpc":"2.0", "params":['$2']}' | jq '.["result"]' > data.json 2>&1 -cat openrpc.json | jq '.["methods"][] | select(.name == "'$1'") | .["result"]["schema"]' > schema.json +cat openrpc.json | jq '.["methods"][] | select(.name == "'$1'") | .["result"]["schema"]["errors"]' > schema.json ajv validate -s schema.json -d data.json # rm schema.json data.json diff --git a/jsonrpc/src/content/results.json b/jsonrpc/src/content/results.json index 21035be8..b25f613a 100644 --- a/jsonrpc/src/content/results.json +++ b/jsonrpc/src/content/results.json @@ -213,7 +213,7 @@ }, "LocalContentResult": { "name": "LocalContentResult", - "description": "Returns the hex encoded content value. If the content is not available, returns \"0x\"", + "description": "Returns the hex encoded content value.", "schema": { "$ref": "#/components/schemas/hexString" } diff --git a/jsonrpc/src/errors/errors.json b/jsonrpc/src/errors/errors.json new file mode 100644 index 00000000..063cab89 --- /dev/null +++ b/jsonrpc/src/errors/errors.json @@ -0,0 +1,13 @@ +{ + "ContentNotFoundError": { + "code": -39001, + "message": "content not found" + }, + "ContentNotFoundErrorWithTrace": { + "code": -39002, + "message": "content not found", + "data": { + "$ref": "#/components/schemas/traceResultObject" + } + } +} diff --git a/jsonrpc/src/methods/beacon.json b/jsonrpc/src/methods/beacon.json index fd241832..db6c5f96 100644 --- a/jsonrpc/src/methods/beacon.json +++ b/jsonrpc/src/methods/beacon.json @@ -142,7 +142,10 @@ ], "result": { "$ref": "#/components/contentDescriptors/RecursiveFindContentResult" - } + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundError" + }] }, { "name": "portal_beaconTraceRecursiveFindContent", @@ -154,7 +157,10 @@ ], "result": { "$ref": "#/components/contentDescriptors/TraceRecursiveFindContentResult" - } + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundErrorWithTrace" + }] }, { "name": "portal_beaconStore", @@ -181,7 +187,10 @@ ], "result": { "$ref": "#/components/contentDescriptors/LocalContentResult" - } + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundError" + }] }, { "name": "portal_beaconGossip", diff --git a/jsonrpc/src/methods/history.json b/jsonrpc/src/methods/history.json index 7ae41299..f0a4b860 100644 --- a/jsonrpc/src/methods/history.json +++ b/jsonrpc/src/methods/history.json @@ -134,7 +134,10 @@ ], "result": { "$ref": "#/components/contentDescriptors/RecursiveFindContentResult" - } + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundError" + }] }, { "name": "portal_historyTraceRecursiveFindContent", @@ -146,7 +149,10 @@ ], "result": { "$ref": "#/components/contentDescriptors/TraceRecursiveFindContentResult" - } + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundErrorWithTrace" + }] }, { "name": "portal_historyStore", @@ -173,7 +179,10 @@ ], "result": { "$ref": "#/components/contentDescriptors/LocalContentResult" - } + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundError" + }] }, { "name": "portal_historyGossip", diff --git a/jsonrpc/src/methods/state.json b/jsonrpc/src/methods/state.json index 2767caf4..c5bb0724 100644 --- a/jsonrpc/src/methods/state.json +++ b/jsonrpc/src/methods/state.json @@ -134,7 +134,25 @@ ], "result": { "$ref": "#/components/contentDescriptors/RecursiveFindContentResult" - } + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundError" + }] + }, + { + "name": "portal_stateTraceRecursiveFindContent", + "summary": "Look up a target content key in the network and get tracing data", + "params": [ + { + "$ref": "#/components/contentDescriptors/ContentKey" + } + ], + "result": { + "$ref": "#/components/contentDescriptors/TraceRecursiveFindContentResult" + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundErrorWithTrace" + }] }, { "name": "portal_stateStore", @@ -161,7 +179,10 @@ ], "result": { "$ref": "#/components/contentDescriptors/LocalContentResult" - } + }, + "errors":[{ + "$ref": "#/components/errors/ContentNotFoundError" + }] }, { "name": "portal_stateGossip",