fix: align audit and dispatch workflows and release failed requests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
import axios from 'axios'
|
||||
import { ApiResponseError, http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
|
||||
export type ContainerCustomsStatus = 'WAITING_CUSTOMER_DOCUMENTS' | 'READY_TO_START' | 'DECLARING' | 'COMPLETED'
|
||||
export type ContainerCustomsTaxMode = 'TAX_REFUND' | 'BUY_DECLARATION'
|
||||
@@ -210,16 +211,45 @@ export async function getContainerCustoms(loadingPlanId: string) {
|
||||
return value ? normalize(value) : null
|
||||
}
|
||||
|
||||
// 报关资料允许下载原始 JSON 文件,仅把统一业务错误信封识别为失败。
|
||||
async function customsDownloadError(blob: Blob, status: number): Promise<ApiResponseError | null> {
|
||||
if (!blob.type.toLowerCase().includes('json')) return null
|
||||
let payload: unknown
|
||||
try { payload = JSON.parse(await blob.text()) } catch { return null }
|
||||
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return null
|
||||
const envelope = payload as Record<string, unknown>
|
||||
if (typeof envelope.code !== 'string' || envelope.code === '200'
|
||||
|| typeof envelope.message !== 'string' || !('data' in envelope)) return null
|
||||
return new ApiResponseError(envelope.message, envelope.code, status, envelope.data,
|
||||
typeof envelope.requestId === 'string' ? envelope.requestId : undefined,
|
||||
typeof envelope.traceId === 'string' ? envelope.traceId : undefined)
|
||||
}
|
||||
|
||||
async function downloadCustomsFile(path: string) {
|
||||
try {
|
||||
const blob = await http.get<Blob, Blob>(path, { responseType: 'blob' })
|
||||
const error = await customsDownloadError(blob, 200)
|
||||
if (error) throw error
|
||||
return blob
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error) && error.response?.data instanceof Blob) {
|
||||
const downloadError = await customsDownloadError(error.response.data, error.response.status)
|
||||
if (downloadError) throw downloadError
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export function downloadContainerCustomsDocument(documentId: string) {
|
||||
return http.get<Blob, Blob>(`${basePath}/documents/${encodeURIComponent(documentId)}/download`, { responseType: 'blob' })
|
||||
return downloadCustomsFile(`${basePath}/documents/${encodeURIComponent(documentId)}/download`)
|
||||
}
|
||||
|
||||
export function downloadContainerCustomsReceipt(documentId: string) {
|
||||
return http.get<Blob, Blob>(`${basePath}/documents/${encodeURIComponent(documentId)}/receipt/download`, { responseType: 'blob' })
|
||||
return downloadCustomsFile(`${basePath}/documents/${encodeURIComponent(documentId)}/completion/download`)
|
||||
}
|
||||
|
||||
export function downloadContainerCustomsFinal(documentId: string) {
|
||||
return http.get<Blob, Blob>(`${basePath}/documents/${encodeURIComponent(documentId)}/final/download`, { responseType: 'blob' })
|
||||
return downloadCustomsFile(`${basePath}/documents/${encodeURIComponent(documentId)}/final/download`)
|
||||
}
|
||||
|
||||
async function action(loadingPlanId: string, name: 'start' | 'send-to-broker' | 'submit-to-broker' | 'complete-all-buy', expectedVersion: number, remark?: string) {
|
||||
|
||||
Reference in New Issue
Block a user