chore: enhance error messaging

This commit is contained in:
Ben Allfree 2024-12-05 10:17:38 +00:00
parent aee53e6143
commit e948d7a2cc
4 changed files with 22 additions and 16 deletions

View File

@ -308,15 +308,15 @@ var HandleMigrateRegions = (e) => {
var HandleInstanceBeforeUpdate = (e) => {
const dao = e.dao || $app.dao();
const log = mkLog(`instances-validate-before-update`);
const id = e.model.getId();
const version = e.model.get("version");
if (!versions.includes(version)) {
throw new BadRequestError(
`Invalid version '${version}'. Version must be one of: ${versions.join(
", "
)}`
);
const msg = `[ERROR] Invalid version '${version}' for [${id}]. Version must be one of: ${versions.join(
", "
)}`;
log(`${msg}`);
throw new BadRequestError(msg);
}
const id = e.model.getId();
const cname = e.model.get("cname");
if (cname.length > 0) {
const result = new DynamicModel({
@ -333,7 +333,9 @@ var HandleInstanceBeforeUpdate = (e) => {
return true;
})();
if (inUse) {
throw new BadRequestError(`Custom domain already in use.`);
const msg = `[ERROR] [${id}] Custom domain ${cname} already in use.`;
log(`${msg}`);
throw new BadRequestError(msg);
}
}
};

View File

@ -1,4 +1,5 @@
module.exports = [
"0.23.*",
"0.22.*",
"0.21.*",
"0.20.*",

View File

@ -6,16 +6,17 @@ export const HandleInstanceBeforeUpdate = (e: core.ModelEvent) => {
const log = mkLog(`instances-validate-before-update`)
const id = e.model.getId()
const version = e.model.get('version')
if (!versions.includes(version)) {
throw new BadRequestError(
`Invalid version '${version}'. Version must be one of: ${versions.join(
', ',
)}`,
)
const msg = `[ERROR] Invalid version '${version}' for [${id}]. Version must be one of: ${versions.join(
', ',
)}`
log(`${msg}`)
throw new BadRequestError(msg)
}
const id = e.model.getId()
const cname = e.model.get('cname')
if (cname.length > 0) {
const result = new DynamicModel({
@ -38,7 +39,9 @@ export const HandleInstanceBeforeUpdate = (e: core.ModelEvent) => {
})()
if (inUse) {
throw new BadRequestError(`Custom domain already in use.`)
const msg = `[ERROR] [${id}] Custom domain ${cname} already in use.`
log(`${msg}`)
throw new BadRequestError(msg)
}
}
}

View File

@ -102,7 +102,7 @@ export const instanceService = mkSingleton(
dbg(`Updated instance fields`, fields)
})
.catch((e) => {
error(`Error updating instance fields`, { fields, e })
error(`Error updating instance fields for ${id}`, { fields, e })
})
},
)
@ -190,7 +190,7 @@ export const instanceService = mkSingleton(
/** Health check */
await tryFetch(`${internalUrl}/api/health`, {
preflight: async () => {
if (stopped()) throw new Error(`Container stopped`)
if (stopped()) throw new Error(`Container stopped ${id}`)
return started()
},
})