From 86d422f9feb2fc00583be9a27e09c18bc03a87f8 Mon Sep 17 00:00:00 2001 From: idanran <96647698+idanran@users.noreply.github.com> Date: Sat, 3 Feb 2024 23:26:42 +0800 Subject: [PATCH] feat: handle `JSON.parse` error (#220) Co-authored-by: Shigma --- src/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index ef05048..5f45c59 100644 --- a/src/index.ts +++ b/src/index.ts @@ -393,8 +393,17 @@ export function apply(ctx: Context, config: Config) { }) if (config.type === 'sd-webui') { - finalPrompt = (JSON.parse((res.data as StableDiffusionWebUI.Response).info)).prompt - return forceDataPrefix((res.data as StableDiffusionWebUI.Response).images[0]) + const data = res.data as StableDiffusionWebUI.Response + if (data?.info?.prompt) { + finalPrompt = data.info.prompt + } else { + try { + finalPrompt = (JSON.parse(data.info)).prompt + } catch (err) { + logger.warn(err) + } + } + return forceDataPrefix(data.images[0]) } if (config.type === 'stable-horde') { const uuid = res.data.id