Commit 188c41b3 authored by Matija Obreza's avatar Matija Obreza

Better error message on deleteDescriptor attempt

parent 4f3d11a1
......@@ -23,6 +23,7 @@ import java.util.UUID;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.exceptions.InvalidApiUsageException;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.filters.DescriptorFilter;
import org.genesys.catalog.model.traits.Descriptor;
......@@ -33,6 +34,7 @@ import org.genesys2.server.api.ApiBaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -259,7 +261,11 @@ public class DescriptorController {
*/
@DeleteMapping(value = "/{UUID},{version}")
public Descriptor deleteDescriptor(@PathVariable("UUID") final UUID uuid, @PathVariable("version") final int version) {
return descriptorService.removeDescriptor(descriptorService.getDescriptor(uuid, version));
try {
return descriptorService.removeDescriptor(descriptorService.getDescriptor(uuid, version));
} catch (DataIntegrityViolationException e) {
throw new InvalidApiUsageException("Cannot delete a referenced descriptor");
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment