feat(datasource-test): v0.11e+ enhanceFromBackend (Phase C2)
datasource/test.ts: - import enhanceFromBackend + formatErrorLine - catch 后端错时 enhanceFromBackend (DB302 数据库连接失败等)
This commit is contained in:
1 parent
7f212f6378
commit
9ee82ac78a
1 file changed
+3
-1
@@ -10,6 +10,7 @@ import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { encryptAesEcb, isEncrypted } from '../../core/crypto.ts'
|
||||
import { initWebapi, loadDataSource } from '../../webapi/dataSource.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
|
||||
interface TestOpts {
|
||||
id?: string
|
||||
@@ -57,7 +58,8 @@ export function buildDatasourceTestCommand(): Command {
|
||||
}
|
||||
const r = (await loadDataSource.testDbConnection(body)) as { code?: number; msg?: string; data?: unknown }
|
||||
if (r.code !== undefined && r.code !== 200) {
|
||||
log.error(`datasource test 失败 (code=${r.code}): ${r.msg}`)
|
||||
const enhanced = enhanceFromBackend(r.msg || '', 'datasource', { entity: 'datasource' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
|
||||
if (opts.json) printJson(r)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user