Improved error handling
This commit is contained in:
parent
7b07f82285
commit
77ca0fd344
3 changed files with 13 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
const util = require("util");
|
||||
const fs = require("fs");
|
||||
|
||||
// random(array) to select a random entry in array
|
||||
exports.random = (array) => {
|
||||
|
@ -22,6 +23,11 @@ exports.clean = async (text) => {
|
|||
.replaceAll("@", `@${String.fromCharCode(8203)}`);
|
||||
|
||||
const { parsed } = require("dotenv").config();
|
||||
const imageServers = JSON.parse(fs.readFileSync("./servers.json", { encoding: "utf8" })).image;
|
||||
|
||||
for (const server of imageServers) {
|
||||
text = text.replaceAll(server, "<redacted>");
|
||||
}
|
||||
|
||||
for (const env of Object.keys(parsed)) {
|
||||
text = text.replaceAll(parsed[env], optionalReplace(parsed[env]));
|
||||
|
|
|
@ -213,13 +213,9 @@ class ImageWorker extends BaseServiceWorker {
|
|||
const num = Math.floor(Math.random() * 100000).toString().slice(0, 5);
|
||||
const timeout = setTimeout(() => {
|
||||
if (this.jobs[num]) delete this.jobs[num];
|
||||
reject("the image request timed out after 25 seconds. Try uploading your image elsewhere.");
|
||||
reject("The image request timed out after 25 seconds. Try uploading your image elsewhere.");
|
||||
}, 25000);
|
||||
this.start(object, num).catch(err => { // incredibly hacky code incoming
|
||||
clearTimeout(timeout);
|
||||
if (err instanceof Error) return reject(err);
|
||||
return err;
|
||||
}).then((data) => {
|
||||
this.start(object, num).then((data) => {
|
||||
clearTimeout(timeout);
|
||||
if (!data.event) reject("Not connected to image server");
|
||||
data.event.once("image", (image, type) => {
|
||||
|
@ -256,7 +252,8 @@ class ImageWorker extends BaseServiceWorker {
|
|||
async handleCommand(data) {
|
||||
try {
|
||||
if (data.type === "run") {
|
||||
return await this.run(data.obj);
|
||||
const result = await this.run(data.obj);
|
||||
return result;
|
||||
} else if (data.type === "reload") {
|
||||
await this.disconnect();
|
||||
await this.repopulate();
|
||||
|
@ -274,7 +271,7 @@ class ImageWorker extends BaseServiceWorker {
|
|||
return await this.getRunning();
|
||||
}
|
||||
} catch (err) {
|
||||
return { err: err.message };
|
||||
return { err: typeof err === "string" ? err : err.message };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue