From c063a215307f5f576fd7c6c5c62955dfdbb0058a Mon Sep 17 00:00:00 2001 From: buzzcode2007 <73412182+buzz_lightsnack_2007@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:20:34 +0800 Subject: [PATCH] add message when API keys are missing --- _locales/en/messages.json | 3 +++ scripts/AI/gemini.js | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 7ee5603..7d9c0d2 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -220,5 +220,8 @@ }, "error_msg_notattached": { "message": "The product data has not been attached to the storage." + }, + "error_msg_APImissing": { + "message": "You have not yet added the API keys. To continue, please add one in the options." } } diff --git a/scripts/AI/gemini.js b/scripts/AI/gemini.js index 5d7a7b1..7ae6f91 100644 --- a/scripts/AI/gemini.js +++ b/scripts/AI/gemini.js @@ -2,6 +2,8 @@ // Import the file module. // import file from `./net.js`; +const texts = (await import(chrome.runtime.getURL("scripts/read.js"))).default; + // Don't forget to set the class as export default. export default class gemini { #key; @@ -15,7 +17,7 @@ export default class gemini { */ constructor (key, model, version = {"API": "v1beta"}) { if ((key) ? (((typeof key).includes(`str`)) ? !(key.trim()) : true) : true) { - throw new Error(`The API key is required.`); + throw new ReferenceError(texts.localized(`error_msg_APImissing`)); }; // Register the API key privately.