31 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import axios from "axios";
import CONFIG from "@/core/config.js";
const deleteContestFile = async (fileId) => {
try {
const token = localStorage.getItem('access_token'); // Получаем токен из localStorage
const response = await axios.delete(
`${CONFIG.BASE_URL}/contest_files/${fileId}/`,
{
withCredentials: true,
headers: {
Authorization: `Bearer ${token}`,
},
}
);
return response.data;
} catch (error) {
const errorMessage = error.response?.data?.detail || error.message;
console.error(`Ошибка удаления файла конкурса с ID ${fileId}:`, errorMessage);
if (error.response?.status === 401) {
throw new Error("Недостаточно прав для удаления файла (401)");
}
if (error.response?.status === 404) {
throw new Error("Файл не найден (404)");
}
throw new Error(errorMessage);
}
};
export default deleteContestFile;