mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-27 05:00:53 +01:00
feat: add conflict handling for duplicate configuration names in save and update processes
This commit is contained in:
@@ -33,7 +33,18 @@ export const pingService = async (url, apiKey, type) => {
|
||||
|
||||
export const saveArrConfig = async config => {
|
||||
try {
|
||||
const response = await axios.post(`/api/arr/config`, config);
|
||||
const response = await axios.post(`/api/arr/config`, config, {
|
||||
validateStatus: status => {
|
||||
return (status >= 200 && status < 300) || status === 409;
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 409) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Configuration with this name already exists'
|
||||
};
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error saving arr config:', error);
|
||||
@@ -41,24 +52,35 @@ export const saveArrConfig = async config => {
|
||||
}
|
||||
};
|
||||
|
||||
export const updateArrConfig = async (id, config) => {
|
||||
try {
|
||||
const response = await axios.put(`/api/arr/config/${id}`, config, {
|
||||
validateStatus: status => {
|
||||
return (status >= 200 && status < 300) || status === 409;
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 409) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Configuration with this name already exists'
|
||||
};
|
||||
}
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error updating arr config:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const getArrConfigs = async () => {
|
||||
try {
|
||||
const response = await axios.get(`/api/arr/config`);
|
||||
console.log('Raw axios response:', response);
|
||||
console.log('Response data:', response.data);
|
||||
return response.data; // This is correct - don't change this
|
||||
} catch (error) {
|
||||
console.error('Error fetching arr configs:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateArrConfig = async (id, config) => {
|
||||
try {
|
||||
const response = await axios.put(`/api/arr/config/${id}`, config);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error updating arr config:', error);
|
||||
console.error('Error fetching arr configs:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user