MCPcopy Create free account
hub / github.com/Web3Auth/Auth / createErrorMiddleware

Function createErrorMiddleware

src/jrpc/jrpc.ts:40–63  ·  view source on GitHub ↗
(log: ConsoleLike)

Source from the content-addressed store, hash-verified

38 * via {@link JRPCEngineV2}.
39 */
40export function createErrorMiddleware(log: ConsoleLike): JRPCMiddleware<JRPCParams, unknown> {
41 return (req, res, next, end) => {
42 try {
43 // json-rpc-engine will terminate the request when it notices this error
44 if (!isValidMethod(req)) {
45 res.error = new SerializableError({ code: errorCodes.rpc.invalidRequest, message: "invalid method" });
46 end();
47 return;
48 }
49 next((done) => {
50 const { error } = res;
51 if (!error) {
52 return done();
53 }
54 log.error(`Auth - RPC Error: ${error.message}`, error);
55 return done();
56 });
57 } catch (error: unknown) {
58 log.error(`Auth - RPC Error thrown: ${(error as Error).message}`, error);
59 res.error = new SerializableError({ code: errorCodes.rpc.internal, message: (error as Error).message });
60 end();
61 }
62 };
63}
64
65/**
66 * @deprecated Part of the JRPC V1 API. Use {@link createEngineStreamV2} instead.

Callers 1

Calls 1

isValidMethodFunction · 0.90

Tested by

no test coverage detected