优化后端代码质量基础

This commit is contained in:
yml2213
2026-05-26 10:48:30 +08:00
parent a2bce8b272
commit d126b35579
13 changed files with 142 additions and 25 deletions
@@ -1,4 +1,5 @@
import { logError, logInfo, logWarn } from '../../utils/logger.js'
import { createHttpError } from '../../utils/http.js'
import {
getCloudtentaclesHealthJob,
getScheduledJobsConfig,
@@ -53,7 +54,10 @@ export async function runScheduledJobNow(jobId: unknown) {
const job = config.jobs.find((item) => String(item.id || '').trim() === String(jobId || '').trim())
if (!job) {
throw new Error('定时任务不存在')
throw createHttpError('定时任务不存在', {
statusCode: 404,
errorCode: 'scheduled_job_not_found',
})
}
const currentTimer = timers.get(job.id)
@@ -171,7 +175,10 @@ function dispatchJob(job: JsonObject) {
return runCloudtentaclesHealthJob(job)
}
throw new Error(`不支持的定时任务类型:${job.type}`)
throw createHttpError(`不支持的定时任务类型:${job.type}`, {
statusCode: 400,
errorCode: 'unsupported_scheduled_job_type',
})
}
function updateJobState(jobId: string, patch: JsonObject) {