fix: export payment client types for production build
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user