Skip to content

Commit a3a0287

Browse files
author
MStarRobotics
committed
fix: Resolve linting errors in contentEngine.ts
1 parent a1dedc6 commit a3a0287

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

services/contentEngine.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { THEME_PROMPTS } from '../constants';
55

66
// Env check - supports both Vite and standard node process.env
77
const viteKey = import.meta.env?.VITE_GEMINI_API_KEY;
8-
const processKey = (globalThis as any)?.process?.env?.VITE_GEMINI_API_KEY || (globalThis as any)?.process?.env?.GEMINI_API_KEY;
8+
// Define valid type structure to avoid 'any'
9+
type EnvWithProcess = { process?: { env?: { VITE_GEMINI_API_KEY?: string; GEMINI_API_KEY?: string } } };
10+
const globalEnv = globalThis as unknown as EnvWithProcess;
11+
const processKey = globalEnv.process?.env?.VITE_GEMINI_API_KEY || globalEnv.process?.env?.GEMINI_API_KEY;
912
const API_KEY = viteKey || processKey;
1013

1114
const initModel = () => {
@@ -85,7 +88,7 @@ export const generateRecipe = async (inputs: RecipeFormData): Promise<Recipe> =>
8588

8689
try {
8790
return JSON.parse(rawText) as Recipe;
88-
} catch (e) {
91+
} catch {
8992
console.error("JSON Parse fail:", rawText);
9093
throw new Error('AI returned invalid JSON. It happens sometimes.');
9194
}
@@ -176,9 +179,19 @@ export const generateRecipeVideo = async (
176179
const blob = await dl.blob();
177180
return URL.createObjectURL(blob);
178181

179-
} catch (err: any) {
182+
} catch (err: unknown) {
180183
// catch any weird google errors
181-
const msg = err?.message || JSON.stringify(err);
184+
let msg = 'Unknown error';
185+
if (err instanceof Error) {
186+
msg = err.message;
187+
} else {
188+
try {
189+
msg = JSON.stringify(err);
190+
} catch {
191+
msg = String(err);
192+
}
193+
}
194+
182195
console.error('Video gen crashed:', msg);
183196
if (msg.includes('API key')) throw new Error('Check API Key permissions.');
184197
throw new Error('Video generation failed. Try again?');

0 commit comments

Comments
 (0)