Merge remote-tracking branch 'origin/master'

This commit is contained in:
2026-02-14 19:57:41 +03:00
parent d0f20674ea
commit a2a756870d
4 changed files with 501 additions and 488 deletions

View File

@@ -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