fix: export payment client types for production build
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled

Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
2026-10-15 09:39:26 +08:00
parent dc2efcde08
commit 68a2b4d892
7 changed files with 97 additions and 14 deletions

View File

@@ -1,9 +1,23 @@
import axios from 'axios'
export class ApiError extends Error {
readonly code?:string
readonly status?:number
constructor(message:string, code?:unknown, status?:unknown) {
super(message)
this.name = 'ApiError'
// Retain bounded machine-readable metadata, never the response/config/request.
if (typeof code === 'string' && /^[a-z][a-z0-9_]{0,63}$/.test(code)) this.code = code
if (typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599) this.status = status
}
}
export const api = axios.create({ baseURL: '/api/v1', timeout: 8000, withCredentials: true })
api.interceptors.response.use((response) => response, (error) => {
const message = error.response?.data?.error?.message || '请求失败,请稍后重试'
return Promise.reject(new Error(message))
const detail = error.response?.data?.error
const message = typeof detail?.message === 'string' && detail.message ? detail.message : '请求失败,请稍后重试'
return Promise.reject(new ApiError(message, detail?.code, error.response?.status))
})
export type Customer = { id:number; name:string; contact_email:string; status:string; created_at:string; updated_at:string }