fix(pl): 司机回执缺品牌数量时仍保存单据,并按业务结果提示成败。
未填写品牌数量不再拦截照片和备注;已填写的品牌数量仍校验。小程序在 HTTP 200 的业务失败下不再弹出保存成功。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
13ed7f5be0
commit
af79aa50a2
7 files changed
+97
-4
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { portalBusinessErrorMessage } from '../portalEnvelope.js'
|
||||
|
||||
test('portal business failure keeps the server message', () => {
|
||||
assert.equal(
|
||||
portalBusinessErrorMessage({
|
||||
code: 400,
|
||||
message: '有品牌产品须填写至少一个品牌数量',
|
||||
data: null
|
||||
}),
|
||||
'有品牌产品须填写至少一个品牌数量'
|
||||
)
|
||||
})
|
||||
|
||||
test('portal success and raw payloads are not errors', () => {
|
||||
assert.equal(
|
||||
portalBusinessErrorMessage({ code: 200, message: 'success', data: { success: true } }),
|
||||
null
|
||||
)
|
||||
assert.equal(portalBusinessErrorMessage({ code: 0, msg: 'ok' }), null)
|
||||
assert.equal(portalBusinessErrorMessage({ id: 'plan-1', planNo: 'PO1' }), null)
|
||||
assert.equal(portalBusinessErrorMessage({ code: 'ABC', name: '地磅单据' }), null)
|
||||
assert.equal(portalBusinessErrorMessage(null), null)
|
||||
})
|
||||
|
||||
test('portal failure without a message still fails', () => {
|
||||
assert.equal(portalBusinessErrorMessage({ code: '400', data: null }), '请求失败')
|
||||
})
|
||||
@@ -1,8 +1,9 @@
|
||||
/**
|
||||
* 地磅模块 HTTP(裸 JSON,非门户 code/data 信封)
|
||||
* 地磅与运输小程序 HTTP。裸 JSON 原样返回;门户信封在 HTTP 200 下若 code 不是 200/0,按业务失败处理。
|
||||
* 对齐 mobile-h5/src/utils/http/db.ts
|
||||
*/
|
||||
import { TOKEN_KEY, REFRESH_TOKEN_KEY, USER_INFO_KEY, resolveApiBase } from '@/config/api'
|
||||
import { portalBusinessErrorMessage } from '@/utils/portalEnvelope'
|
||||
|
||||
const DB_COLLECTION_ROOT = /^\/(plans|inventory|weighing)$/
|
||||
|
||||
@@ -83,6 +84,14 @@ export function dbRequest(options = {}) {
|
||||
return
|
||||
}
|
||||
if (status >= 200 && status < 300) {
|
||||
const businessError = portalBusinessErrorMessage(data)
|
||||
if (businessError) {
|
||||
if (showError) {
|
||||
uni.showToast({ title: businessError.slice(0, 40), icon: 'none' })
|
||||
}
|
||||
reject(new Error(businessError))
|
||||
return
|
||||
}
|
||||
resolve(data)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 门户信封 { code, message, data } 的业务失败文案。
|
||||
* HTTP 200 仍可能携带 code=400;code 缺失或非数字时视为裸 JSON。
|
||||
* @param {unknown} data
|
||||
* @returns {string | null}
|
||||
*/
|
||||
export function portalBusinessErrorMessage(data) {
|
||||
if (!data || typeof data !== 'object' || Array.isArray(data)) return null
|
||||
if (!Object.prototype.hasOwnProperty.call(data, 'code')) return null
|
||||
const code = Number(data.code)
|
||||
if (!Number.isFinite(code) || code === 200 || code === 0) return null
|
||||
const message = typeof data.message === 'string' ? data.message.trim() : ''
|
||||
const msg = typeof data.msg === 'string' ? data.msg.trim() : ''
|
||||
return message || msg || '请求失败'
|
||||
}
|
||||
Reference in new issue
Block a user