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

View File

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