subagents
This commit is contained in:
@@ -196,6 +196,33 @@ async function postApi(endpoint, body) {
|
||||
}
|
||||
// [/DEF:postApi:Function]
|
||||
|
||||
// [DEF:deleteApi:Function]
|
||||
// @PURPOSE: Generic DELETE request wrapper.
|
||||
// @PRE: endpoint is provided.
|
||||
// @POST: Returns Promise resolving to JSON data or throws on error.
|
||||
// @PARAM: endpoint (string) - API endpoint.
|
||||
// @RETURN: Promise<any> - JSON response.
|
||||
async function deleteApi(endpoint) {
|
||||
try {
|
||||
console.log(`[api.deleteApi][Action] Deleting from context={{'endpoint': '${endpoint}'}}`);
|
||||
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
console.log(`[api.deleteApi][Action] Received response context={{'status': ${response.status}, 'ok': ${response.ok}}}`);
|
||||
if (!response.ok) {
|
||||
throw await buildApiError(response);
|
||||
}
|
||||
if (response.status === 204) return null;
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error(`[api.deleteApi][Coherence:Failed] Error deleting from ${endpoint}:`, error);
|
||||
notifyApiError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
// [/DEF:deleteApi:Function]
|
||||
|
||||
// [DEF:requestApi:Function]
|
||||
// @PURPOSE: Generic request wrapper.
|
||||
// @PRE: endpoint and method are provided.
|
||||
@@ -237,6 +264,7 @@ async function requestApi(endpoint, method = 'GET', body = null) {
|
||||
export const api = {
|
||||
fetchApi,
|
||||
postApi,
|
||||
deleteApi,
|
||||
requestApi,
|
||||
getPlugins: () => fetchApi('/plugins'),
|
||||
getTasks: (options = {}) => {
|
||||
|
||||
Reference in New Issue
Block a user