MCPcopy
hub / github.com/e-p-armstrong/augmentoolkit / handleApiResponse

Function handleApiResponse

atk-interface/src/api.js:6–36  ·  view source on GitHub ↗
(response)

Source from the content-addressed store, hash-verified

4
5// Helper to handle common fetch logic and errors
6async function handleApiResponse(response) {
7 if (!response.ok) {
8 let errorMsg = `API Error: ${response.status} ${response.statusText}`;
9 let errorData = null;
10 try {
11 // Attempt to parse error detail from backend
12 errorData = await response.json();
13 errorMsg = errorData.detail || JSON.stringify(errorData) || errorMsg;
14 } catch (e) {
15 // If parsing fails, try reading as text
16 try {
17 errorMsg = await response.text() || errorMsg;
18 } catch (textError) { /* Ignore text reading error */ }
19 }
20 console.error('API Error Data:', errorData);
21 const error = new Error(errorMsg);
22 error.status = response.status;
23 error.data = errorData;
24 throw error;
25 }
26 // If response has content, parse as JSON, otherwise return the response object
27 const contentType = response.headers.get("content-type");
28 if (contentType && contentType.indexOf("application/json") !== -1) {
29 return response.json();
30 }
31 if (contentType && contentType.indexOf("text/") !== -1) {
32 return response.text(); // Handle text responses like config content
33 }
34 // For downloads or other types, return the raw response
35 return response;
36}
37
38// --- Config API ---
39

Callers 9

fetchConfigStructureFunction · 0.85
fetchConfigContentFunction · 0.85
saveConfigContentFunction · 0.85
createConfigDirectoryFunction · 0.85
deleteConfigItemFunction · 0.85
moveConfigItemFunction · 0.85
duplicateConfigFunction · 0.85
runPipelineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected