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) => { var HandleInstanceBeforeUpdate = (e) => {
const dao = e.dao || $app.dao(); const dao = e.dao || $app.dao();
const log = mkLog(`instances-validate-before-update`); const log = mkLog(`instances-validate-before-update`);
const id = e.model.getId();
const version = e.model.get("version"); const version = e.model.get("version");
if (!versions.includes(version)) { if (!versions.includes(version)) {
throw new BadRequestError( const msg = `[ERROR] Invalid version '${version}' for [${id}]. Version must be one of: ${versions.join(
`Invalid version '${version}'. Version must be one of: ${versions.join( ", "
", " )}`;
)}` log(`${msg}`);
); throw new BadRequestError(msg);
} }
const id = e.model.getId();
const cname = e.model.get("cname"); const cname = e.model.get("cname");
if (cname.length > 0) { if (cname.length > 0) {
const result = new DynamicModel({ const result = new DynamicModel({
@ -333,7 +333,9 @@ var HandleInstanceBeforeUpdate = (e) => {
return true; return true;
})(); })();
if (inUse) { 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 = [ module.exports = [
"0.23.*",
"0.22.*", "0.22.*",
"0.21.*", "0.21.*",
"0.20.*", "0.20.*",

View File

@ -6,16 +6,17 @@ export const HandleInstanceBeforeUpdate = (e: core.ModelEvent) => {
const log = mkLog(`instances-validate-before-update`) const log = mkLog(`instances-validate-before-update`)
const id = e.model.getId()
const version = e.model.get('version') const version = e.model.get('version')
if (!versions.includes(version)) { if (!versions.includes(version)) {
throw new BadRequestError( const msg = `[ERROR] Invalid version '${version}' for [${id}]. Version must be one of: ${versions.join(
`Invalid version '${version}'. Version must be one of: ${versions.join( ', ',
', ', )}`
)}`, log(`${msg}`)
) throw new BadRequestError(msg)
} }
const id = e.model.getId()
const cname = e.model.get('cname') const cname = e.model.get('cname')
if (cname.length > 0) { if (cname.length > 0) {
const result = new DynamicModel({ const result = new DynamicModel({
@ -38,7 +39,9 @@ export const HandleInstanceBeforeUpdate = (e: core.ModelEvent) => {
})() })()
if (inUse) { 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) dbg(`Updated instance fields`, fields)
}) })
.catch((e) => { .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 */ /** Health check */
await tryFetch(`${internalUrl}/api/health`, { await tryFetch(`${internalUrl}/api/health`, {
preflight: async () => { preflight: async () => {
if (stopped()) throw new Error(`Container stopped`) if (stopped()) throw new Error(`Container stopped ${id}`)
return started() return started()
}, },
}) })