Simplify instance details and clarify diagnostics
This commit is contained in:
@@ -52,8 +52,9 @@ export function createLogRefresh(options: Options) {
|
||||
try {
|
||||
const response = await request(`/api/servers/${encodeURIComponent(target.server)}/logs/${encodeURIComponent(target.key)}?lines=${target.lines}`,
|
||||
{ signal: entry.controller.signal, cache: 'no-store' });
|
||||
const body = await response.json() as LogResponse;
|
||||
if (!response.ok || !body.ok) throw new Error(body.reason ?? 'Could not refresh log.');
|
||||
const body = await response.json().catch(() => null) as LogResponse | null;
|
||||
if (!response.ok || !body?.ok) throw new Error(body?.reason ?? `HTTP ${response.status}: ${body ? 'Log request failed.' : 'Expected a JSON log response.'}`);
|
||||
if (!Array.isArray(body.lines) || !body.lines.every(line => typeof line === 'string')) throw new Error('Invalid log response: expected an array of lines.');
|
||||
if (current()) { options.onError(''); options.onData(target.key, body); }
|
||||
} catch (error) {
|
||||
if (current() && !entry.controller.signal.aborted) options.onError(error instanceof Error ? error.message : 'Could not refresh log.');
|
||||
|
||||
Reference in New Issue
Block a user