@@ -133,10 +133,12 @@ export const getFetch: NodeTaskFactory<NodeInfo> = (
133133 try {
134134 sendFetchState ( 'fetching' ) ;
135135
136- const openAIKey = canvasAppInstance ?. isContextOnly
137- ? process . env ?. [ 'openai_api_key' ] ?? ''
138- : canvasAppInstance ?. getTempData ( 'openai-key' ) ?? '' ;
139-
136+ // const openAIKey = canvasAppInstance?.isContextOnly
137+ // ? (typeof process !== 'undefined' &&
138+ // process?.env?.['openai_api_key']) ??
139+ // ''
140+ // : canvasAppInstance?.getTempData('openai-key') ?? '';
141+ const openAIKey = canvasAppInstance ?. getTempData ( 'openai-key' ) ?? '' ;
140142 let url = node ?. nodeInfo ?. formValues ?. [ 'url' ] ?? '' ;
141143 if ( url . startsWith ( '/' ) ) {
142144 url = canvasAppInstance ?. getApiUrlRoot ( ) + url . substring ( 1 ) ;
@@ -268,6 +270,23 @@ export const getFetch: NodeTaskFactory<NodeInfo> = (
268270 contentType . includes ( 'application/json' )
269271 ) {
270272 response . json ( ) . then ( ( json ) => {
273+ if ( response . status >= 400 ) {
274+ sendFetchState ( 'error' ) ;
275+ result = undefined ;
276+ if (
277+ ( errorNode ?. domElement as unknown as HTMLElement ) &&
278+ ! canvasAppInstance ?. isContextOnly
279+ ) {
280+ (
281+ errorNode ?. domElement as unknown as HTMLElement
282+ ) ?. classList . remove ( 'hidden' ) ;
283+ (
284+ errorNode . domElement as unknown as HTMLElement
285+ ) . textContent = json ?. error ?. toString ( ) ?? 'Error' ;
286+ }
287+ sendError ( json ?. error ?. message ?. toString ( ) ?? 'Error' ) ;
288+ return ;
289+ }
271290 sendFetchState ( 'ready' ) ;
272291 result = json ;
273292 hideLoader ( ) ;
0 commit comments