Integrate backend APIs and move review to center editor tab
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
export class ApiHttpClient {
|
||||
constructor(baseUrl = null) {
|
||||
const envBase = window.__API_BASE_URL__ || null;
|
||||
this.baseUrl = (baseUrl || envBase || "http://localhost:8081").replace(/\/$/, "");
|
||||
}
|
||||
|
||||
async request(path, options = {}) {
|
||||
const response = await fetch(`${this.baseUrl}${path}`, {
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(options.headers || {})
|
||||
}
|
||||
});
|
||||
const isJson = (response.headers.get("content-type") || "").includes("application/json");
|
||||
const body = isJson ? await response.json() : null;
|
||||
if (!response.ok) {
|
||||
const desc = body?.desc || body?.detail || `HTTP ${response.status}`;
|
||||
throw new Error(desc);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user