Skip to content

Commit d58eba5

Browse files
committed
Fix login failure and preserve server error messages
- api/v1/ping returns text/plain 'pong'; returning undefined for non-JSON responses caused useAuthStore.setUser to always throw 'Authentication failed'. Now return the text body when non-JSON. - On non-2xx responses, read the body and attach it as err.response = { status, data } so existing callers (e.g. Editor.vue) can surface the server-provided message via err.response.data.message, matching the previous axios shape.
1 parent e51ba46 commit d58eba5

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

kyuubi-server/web-ui/src/utils/request.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,22 @@ async function request(config: RequestConfig): Promise<unknown> {
6969
throw new Error('Unauthorized')
7070
}
7171

72-
if (!response.ok) {
73-
throw new Error(`HTTP error! status: ${response.status}`)
74-
}
72+
const contentType = response.headers.get('content-type') || ''
73+
const isJson = contentType.includes('application/json')
74+
const rawText = await response.text()
75+
const parsedBody = isJson && rawText ? JSON.parse(rawText) : rawText || undefined
7576

76-
const contentType = response.headers.get('content-type')
77-
if (!contentType || !contentType.includes('application/json')) {
78-
return undefined
77+
if (!response.ok) {
78+
const message =
79+
(parsedBody && typeof parsedBody === 'object' && (parsedBody as any).message) ||
80+
(typeof parsedBody === 'string' && parsedBody) ||
81+
`HTTP error! status: ${response.status}`
82+
const err: any = new Error(message)
83+
err.response = { status: response.status, data: parsedBody }
84+
throw err
7985
}
8086

81-
const text = await response.text()
82-
return text ? JSON.parse(text) : undefined
87+
return parsedBody
8388
}
8489

8590
export default request

0 commit comments

Comments
 (0)