Pass the error out to the processor

This commit is contained in:
buzz-lightsnack-2007 2024-05-04 10:40:16 +08:00
parent 6cbec224b6
commit dccdd48cfc

View file

@ -52,9 +52,6 @@ export default class product {
// Stop when not attached (basically, not entirely initialized).
if (!this.#snip) {throw new ReferenceError((new texts(`error_msg_notattached`)).localized)};
// Write the data to the session storage, indicating that it is the last edited.
(this[`analysis`]) ? await session.write([`sites`, this.URL, `analysis`], this.analysis) : false;
// There is only a need to save the data if an update is needed.
if (this.status[`update`]) {
// Save the data to the storage.
@ -81,24 +78,19 @@ export default class product {
// Add the prompt.
PROMPT.push({"text": ((new texts(`AI_message_prompt`)).localized).concat(JSON.stringify(this.details))});
try {
// Run the analysis.
await analyzer.generate(PROMPT);
// Run the analysis.
await analyzer.generate(PROMPT);
// Raise an error if the product analysis is blocked.
if (analyzer.blocked) {
throw new Error((new texts(`error_msg_blocked`)).localized)
};
// Raise an error if the product analysis is blocked.
if (analyzer.blocked) {
throw new Error((new texts(`error_msg_blocked`)).localized)
};
if (analyzer.candidate) {
// Remove all markdown formatting.
this.analysis = JSON.parse(analyzer.candidate.replace(/(```json|```|`)/g, ''));
};
if (analyzer.candidate) {
// Remove all markdown formatting.
this.analysis = JSON.parse(analyzer.candidate.replace(/(```json|```|`)/g, ''));
};
} catch(err) {
await session.write([`sites`, this.URL, `error`], err, 1);
throw err;
}
};
return(this.analysis);