Update frontend requests

This commit is contained in:
2024-12-04 21:33:34 +01:00
parent dc8fc6c225
commit 3d36c67c90
2 changed files with 14 additions and 15 deletions

View File

@@ -47,17 +47,16 @@ export const saveFileContent = async (workspaceName, filePath, content) => {
body: content,
}
);
return response.text();
return response.json();
};
export const deleteFile = async (workspaceName, filePath) => {
const response = await apiCall(
await apiCall(
`${API_BASE_URL}/workspaces/${workspaceName}/files/${filePath}`,
{
method: 'DELETE',
}
);
return response.text();
};
export const getWorkspace = async (workspaceName) => {
@@ -119,17 +118,13 @@ export const lookupFileByName = async (workspaceName, filename) => {
};
export const updateLastOpenedFile = async (workspaceName, filePath) => {
const response = await apiCall(
`${API_BASE_URL}/workspaces/${workspaceName}/files/last`,
{
await apiCall(`${API_BASE_URL}/workspaces/${workspaceName}/files/last`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ filePath }),
}
);
return response.json();
});
};
export const getLastOpenedFile = async (workspaceName) => {

View File

@@ -49,13 +49,17 @@ export const apiCall = async (url, options = {}) => {
throw new Error('Authentication failed');
}
if (!response.ok) {
if (!response.ok && response.status !== 204) {
const errorData = await response.json().catch(() => null);
throw new Error(
errorData?.message || `HTTP error! status: ${response.status}`
);
}
if (response.status === 204) {
return null;
}
return response;
} catch (error) {
console.error(`API call failed: ${error.message}`);