The recipes.blue monorepo recipes.blue
recipes appview atproto

fix: use error middleware to catch new hono-ized xrpcerrors

+12 -14
+3
apps/api/src/index.ts
··· 7 7 import { ZodError } from "zod"; 8 8 import * as Sentry from "@sentry/node" 9 9 import { recipeApp } from "./recipes/index.js"; 10 + import { XRPCError } from "./util/xrpc.js"; 10 11 11 12 if (env.SENTRY_DSN) { 12 13 Sentry.init({ ··· 47 48 error: 'invalid_data', 48 49 message: e.message, 49 50 }); 51 + } else if (e instanceof XRPCError) { 52 + return e.hono(ctx); 50 53 } 51 54 52 55 ctx.status(500);
+9 -14
apps/api/src/recipes/index.ts
··· 12 12 throw new XRPCError('this endpoint requires authentication', 'authz_required', 401); 13 13 } 14 14 15 - try { 16 - const serviceJwt = await verifyJwt( 17 - authz.split(' ')[1]!, 18 - 'did:web:recipes.blue#api', 19 - null, 20 - async (iss, forceRefresh) => { 21 - console.log(iss); 22 - return ''; 23 - }, 24 - ); 25 - } catch(e) { 26 - if (e instanceof XRPCError) return e.hono(ctx); 27 - throw e; 28 - } 15 + const serviceJwt = await verifyJwt( 16 + authz.split(' ')[1]!, 17 + 'did:web:recipes.blue#api', 18 + null, 19 + async (iss, forceRefresh) => { 20 + console.log(iss); 21 + return ''; 22 + }, 23 + ); 29 24 30 25 //const agent = await getSessionAgent(ctx); 31 26 //if (!agent) {