From ee9e001fcc9cec48f5cfefbaff7051b07c46e31b Mon Sep 17 00:00:00 2001 From: lucio Date: Wed, 8 Apr 2020 16:45:56 +0200 Subject: [PATCH] fixed a bug on Exception catching on Collector stubs --- .../publisher/stubs/registry/CollectorStubs.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/CollectorStubs.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/CollectorStubs.java index dec6fac..ca7f48d 100644 --- a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/CollectorStubs.java +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/CollectorStubs.java @@ -24,7 +24,7 @@ public class CollectorStubs implements RegistryStub { public static final String TOKEN_HEADER_ENTRY = "gcube-token"; public static final String SCOPE_HEADER_ENTRY = "gcube-scope"; - + private String endopoint; public CollectorStubs(String endopoint) { @@ -51,7 +51,7 @@ public class CollectorStubs implements RegistryStub { if (connection.getResponseCode()!=200) throw new CreateException("error creating resource "+connection.getResponseCode()); }catch (Exception e) { log.error("error on create",e); - throw new RemoveException(e.getMessage()); + throw new CreateException(e.getMessage()); } } @@ -74,7 +74,7 @@ public class CollectorStubs implements RegistryStub { if (connection.getResponseCode()!=200) throw new UpdateException("error updating resource "+connection.getResponseCode()); }catch (Exception e) { log.error("error on update",e); - throw new RemoveException(e.getMessage()); + throw new UpdateException(e.getMessage()); } } @@ -91,11 +91,12 @@ public class CollectorStubs implements RegistryStub { log.info("response code is not 200"); if (connection.getResponseCode()==404) throw new ResourceDoesNotExistException("resource with id "+id+" not found"); - else throw new RemoveException("error removing resource with id "+id); + else throw new RemoveException("generic error removing resource "+id); } + }catch (ResourceDoesNotExistException | RemoveException e) { + throw e; }catch (Exception e) { - log.error("error on remove",e); - throw new RemoveException(e.getMessage()); + throw new RemoveException("connection error removing resource"); } } @@ -112,7 +113,7 @@ public class CollectorStubs implements RegistryStub { else if (SecurityTokenProvider.instance.get()!=null) connection.setRequestProperty(TOKEN_HEADER_ENTRY,SecurityTokenProvider.instance.get()); else throw new RuntimeException("Collector requires authorization (via token or scope)"); - + connection.setRequestMethod(method); return connection; }