mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-10 10:43:01 +02:00
Better error rendering
This commit is contained in:
+12
-2
@@ -26,8 +26,18 @@ async function fetchJson<T>(url: string, options?: RequestInit): Promise<T> {
|
||||
},
|
||||
});
|
||||
if (!res.ok) {
|
||||
const error = await res.text();
|
||||
throw new Error(error || res.statusText);
|
||||
const errorText = await res.text();
|
||||
// FastAPI returns errors as {"detail": "message"}, extract the message
|
||||
let errorMessage = errorText || res.statusText;
|
||||
try {
|
||||
const errorJson = JSON.parse(errorText);
|
||||
if (errorJson.detail) {
|
||||
errorMessage = errorJson.detail;
|
||||
}
|
||||
} catch {
|
||||
// Not JSON, use raw text
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user