kin: KIN-083 Healthcheck claude CLI auth: перед запуском pipeline проверять что claude залогинен (быстрый claude -p 'ok' --output-format json, проверить is_error и 'Not logged in'). Если не залогинен — не запускать pipeline, а показать ошибку 'Claude CLI requires login' в GUI с инструкцией.
This commit is contained in:
parent
a80679ae72
commit
bfc8f1c0bb
18 changed files with 1390 additions and 57 deletions
|
|
@ -1,8 +1,28 @@
|
|||
const BASE = '/api'
|
||||
|
||||
export class ApiError extends Error {
|
||||
code: string
|
||||
constructor(code: string, message: string) {
|
||||
super(message)
|
||||
this.name = 'ApiError'
|
||||
this.code = code
|
||||
}
|
||||
}
|
||||
|
||||
async function throwApiError(res: Response): Promise<never> {
|
||||
let code = ''
|
||||
let msg = `${res.status} ${res.statusText}`
|
||||
try {
|
||||
const data = await res.json()
|
||||
if (data.error) code = data.error
|
||||
if (data.message) msg = data.message
|
||||
} catch {}
|
||||
throw new ApiError(code, msg)
|
||||
}
|
||||
|
||||
async function get<T>(path: string): Promise<T> {
|
||||
const res = await fetch(`${BASE}${path}`)
|
||||
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
|
||||
if (!res.ok) await throwApiError(res)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
|
|
@ -12,7 +32,7 @@ async function patch<T>(path: string, body: unknown): Promise<T> {
|
|||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
|
||||
if (!res.ok) await throwApiError(res)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +42,7 @@ async function post<T>(path: string, body: unknown): Promise<T> {
|
|||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
|
||||
if (!res.ok) await throwApiError(res)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue