Skip to content
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
2 changes: 1 addition & 1 deletion noir-projects/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VERSION 0.8
test:
BUILD +test-protocol-circuits
BUILD +test-aztec-nr
# BUILD +test-contracts
BUILD +test-contracts

test-protocol-circuits:
FROM ../+bootstrap
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/bot/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { type BotRunner } from './runner.js';
* @returns An JSON-RPC HTTP server
*/
export function createBotRunnerRpcServer(botRunner: BotRunner) {
createSafeJsonRpcServer(botRunner, BotRunnerApiSchema, botRunner.isHealthy.bind(botRunner));
createSafeJsonRpcServer(botRunner, BotRunnerApiSchema, false, botRunner.isHealthy.bind(botRunner));
}

export function getBotRunnerApiHandler(botRunner: BotRunner): ApiHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export class SafeJsonRpcServer {
constructor(
/** The proxy object to delegate requests to. */
private readonly proxy: Proxy,
/**
* Return an HTTP 200 status code on errors, but include an error object
* as per the JSON RPC spec
*/
private http200OnError = false,
/** Health check function */
private readonly healthCheck: StatusCheckFn = () => true,
/** Logger */
Expand Down Expand Up @@ -105,9 +110,17 @@ export class SafeJsonRpcServer {
ctx.status = 400;
ctx.body = { jsonrpc, id, error: { code: -32601, message: `Method not found: ${method}` } };
} else {
const result = await this.proxy.call(method, params);
ctx.body = { jsonrpc, id, result };
ctx.status = 200;
try {
const result = await this.proxy.call(method, params);
ctx.body = { jsonrpc, id, result };
} catch (err: any) {
if (this.http200OnError) {
ctx.body = { jsonrpc, id, error: { code: err.code || -32600, data: err.data, message: err.message } };
} else {
throw err;
}
}
}
});

Expand Down Expand Up @@ -259,20 +272,22 @@ function makeAggregateHealthcheck(namedHandlers: NamespacedApiHandlers, log?: Lo
*/
export function createNamespacedSafeJsonRpcServer(
handlers: NamespacedApiHandlers,
http200OnError = false,
log = createLogger('json-rpc:server'),
): SafeJsonRpcServer {
const proxy = new NamespacedSafeJsonProxy(handlers);
const healthCheck = makeAggregateHealthcheck(handlers, log);
return new SafeJsonRpcServer(proxy, healthCheck, log);
return new SafeJsonRpcServer(proxy, http200OnError, healthCheck, log);
}

export function createSafeJsonRpcServer<T extends object = any>(
handler: T,
schema: ApiSchemaFor<T>,
http200OnError = false,
healthCheck?: StatusCheckFn,
) {
const proxy = new SafeJsonProxy(handler, schema);
return new SafeJsonRpcServer(proxy, healthCheck);
return new SafeJsonRpcServer(proxy, http200OnError, healthCheck);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/txe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ const TXEDispatcherApiSchema: ApiSchemaFor<TXEDispatcher> = {
* @returns A TXE RPC server.
*/
export function createTXERpcServer(logger: Logger) {
return createSafeJsonRpcServer(new TXEDispatcher(logger), TXEDispatcherApiSchema);
return createSafeJsonRpcServer(new TXEDispatcher(logger), TXEDispatcherApiSchema, true);
}