From 3fd3a4fc9d2bc28394f3a2c62297fb8189ede4e7 Mon Sep 17 00:00:00 2001 From: Abdullah Alfaraj <7842232+AbdullahAlfaraj@users.noreply.github.com> Date: Sun, 19 Nov 2023 03:02:51 +0300 Subject: [PATCH] Display error to the user if comfyui api failed to get object info --- typescripts/comfyui/comfyapi.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/typescripts/comfyui/comfyapi.ts b/typescripts/comfyui/comfyapi.ts index dc9c43ff..9a1dac52 100644 --- a/typescripts/comfyui/comfyapi.ts +++ b/typescripts/comfyui/comfyapi.ts @@ -1,3 +1,4 @@ +import { app } from 'photoshop' import settings_tab from '../settings/settings' import { requestGet, requestPost } from '../util/ts/api' import { base64UrlToBase64 } from '../util/ts/general' @@ -20,12 +21,21 @@ export interface ComfyResult { class ComfyAPI { private object_info: Record = {} comfy_url: string + status: boolean = false + constructor(comfy_url: string) { this.comfy_url = comfy_url } async init() { - this.object_info = await this.getObjectInfo(this.comfy_url) - return this.object_info + try { + this.object_info = await this.getObjectInfo(this.comfy_url) + this.status = true + return this.object_info + } catch (e) { + console.error(e) + app.showAlert(`${e}`) + this.status = false + } } setUrl(comfy_url: string) { this.comfy_url = comfy_url @@ -74,10 +84,14 @@ class ComfyAPI { async getObjectInfo(comfy_url: string) { try { - const object_info = await requestGet(`${comfy_url}/object_info`) + const full_url = `${comfy_url}/object_info` + const object_info = await requestGet(full_url) + if (!object_info) + throw `can not request from comfyui url: ${comfy_url}` return object_info } catch (e) { console.error(e) + throw e } } getReadableError(result: ComfyResult): string {