Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -37,6 +37,17 @@ let isLoggingOut = false
|
||||
api.interceptors.response.use(
|
||||
r => r,
|
||||
async (error) => {
|
||||
const status = error?.response?.status
|
||||
const hasBlob = typeof Blob !== 'undefined' && error?.response?.data instanceof Blob
|
||||
|
||||
if ((status >= 500 || hasBlob) && error) {
|
||||
const method = String(error?.config?.method || 'GET').toUpperCase()
|
||||
const url = error?.config?.url || ''
|
||||
const detail = await extractApiErrorDetail(error)
|
||||
error.parsedMessage = detail
|
||||
console.error(`❌ API ${status || '-'} ${method} ${url}: ${detail}`)
|
||||
}
|
||||
|
||||
if (error?.response?.status === 401 && !isLoggingOut) {
|
||||
isLoggingOut = true
|
||||
try {
|
||||
@@ -98,23 +109,31 @@ async function parseBlobErrorMessage(data) {
|
||||
return ''
|
||||
}
|
||||
|
||||
export async function extractApiErrorDetail(err) {
|
||||
let detail =
|
||||
err?.parsedMessage ||
|
||||
err?.response?.data?.detail ||
|
||||
err?.response?.data?.message ||
|
||||
err?.response?.data?.error ||
|
||||
''
|
||||
|
||||
if (!detail) {
|
||||
detail = await parseBlobErrorMessage(err?.response?.data)
|
||||
}
|
||||
|
||||
if (!detail) {
|
||||
detail = err?.message || 'Request failed'
|
||||
}
|
||||
|
||||
return detail
|
||||
}
|
||||
|
||||
export const download = async (u, p = {}, c = {}) => {
|
||||
try {
|
||||
const r = await api.get(u, { params: p, responseType: 'blob', ...c })
|
||||
return r.data
|
||||
} catch (err) {
|
||||
let detail =
|
||||
err?.response?.data?.detail ||
|
||||
err?.response?.data?.message ||
|
||||
''
|
||||
|
||||
if (!detail) {
|
||||
detail = await parseBlobErrorMessage(err?.response?.data)
|
||||
}
|
||||
|
||||
if (!detail) {
|
||||
detail = err?.message || 'Download failed'
|
||||
}
|
||||
const detail = await extractApiErrorDetail(err)
|
||||
|
||||
const wrapped = new Error(detail)
|
||||
wrapped.status = err?.response?.status
|
||||
|
||||
Reference in New Issue
Block a user