feat(print-info): v0.11e+ enhanceFromBackend (Phase C2)
print/info.ts: - import enhanceFromBackend + formatErrorLine - 后端 API 失败 + 数据为空 两种情况都用 enhanceFromBackend
This commit is contained in:
1 parent
fdcb377fb5
commit
9ec9eb49c3
1 file changed
+5
-2
@@ -7,6 +7,7 @@ import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
|
||||
interface InfoOpts {
|
||||
id: string
|
||||
@@ -22,11 +23,13 @@ export function buildPrintInfoCommand(): Command {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.get<Record<string, unknown>>(`/system/printDev/${opts.id}`)
|
||||
if (r.code !== 200) {
|
||||
log.error(`print info 失败 (code=${r.code}): ${r.msg}`)
|
||||
const enhanced = enhanceFromBackend(r.msg || '', 'print', { entity: 'print' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (!r.data) {
|
||||
log.error(`print id=${opts.id} 不存在`)
|
||||
const enhanced = enhanceFromBackend('打印模板 id 不存在', 'id', { entity: 'print' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
}
|
||||
if (opts.json) {
|
||||
|
||||
Reference in new issue
Block a user