From 1ddcebfa15eaee1d57b8510f665f1c3baf58e1fc Mon Sep 17 00:00:00 2001 From: Tom Meagher Date: Thu, 8 Feb 2024 15:28:19 -0500 Subject: [PATCH] fix: parse error --- src/index.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 9c4cbc4e..ee9ba871 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -47,15 +47,16 @@ export class Framework extends Hono { path: string, handler: ( context: FrameContext, - previousContext: FrameContext, + previousContext?: FrameContext | undefined, ) => FrameHandlerReturnType | Promise, ) { // Frame Route (implements GET & POST). this.use(path, async (c) => { const query = c.req.query() - const previousContext = deserializeJson( - query.previousContext, - ) + const previousContext = + query.previousContext && query.previousContext !== 'undefined' + ? deserializeJson(query.previousContext) + : undefined const context = await getFrameContext(c) const { intents } = await handler(context, previousContext) @@ -98,9 +99,10 @@ export class Framework extends Hono { this.get(`${toBaseUrl(path)}/image`, async (c) => { const query = c.req.query() const parsedContext = deserializeJson(query.context) - const parsedPreviousContext = deserializeJson( - query.previousContext, - ) + const parsedPreviousContext = + query.previousContext && query.previousContext !== 'undefined' + ? deserializeJson(query.previousContext) + : undefined const { image } = await handler(parsedContext, parsedPreviousContext) return new ImageResponse(image) })