From 4bc8ec55f7539c314044f668c3ce95242543f98e Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Tue, 7 Jan 2020 17:49:55 -0500 Subject: [PATCH] normalize storage errors --- .../bubble/resources/cloud/StorageResource.java | 17 ++++++++++------- .../post_auth/ResourceMessages.properties | 3 --- .../server/pre_auth/ResourceMessages.properties | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bubble-server/src/main/java/bubble/resources/cloud/StorageResource.java b/bubble-server/src/main/java/bubble/resources/cloud/StorageResource.java index c1ac1486..f62d85a3 100644 --- a/bubble-server/src/main/java/bubble/resources/cloud/StorageResource.java +++ b/bubble-server/src/main/java/bubble/resources/cloud/StorageResource.java @@ -22,8 +22,7 @@ import java.util.concurrent.atomic.AtomicReference; import static bubble.ApiConstants.*; import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA; -import static org.cobbzilla.util.daemon.ZillaRuntime.die; -import static org.cobbzilla.util.daemon.ZillaRuntime.empty; +import static org.cobbzilla.util.daemon.ZillaRuntime.*; import static org.cobbzilla.util.http.HttpContentTypes.*; import static org.cobbzilla.util.io.FileUtil.basename; import static org.cobbzilla.wizard.resources.ResourceUtil.*; @@ -70,7 +69,11 @@ public class StorageResource { if (in == null) return notFound(key); final String contentType = metadata.hasContentType() ? metadata.getContentType() : APPLICATION_OCTET_STREAM; - return stream(contentType, in); + try { + return stream(contentType, in); + } catch (Exception e) { + return invalid("err.read.failed", "read failed for prefix: "+key, key); + } } @GET @Path(EP_LIST+"/{key : .+}") @@ -82,7 +85,7 @@ public class StorageResource { try { return ok(driver.list(thisNodeUuid(), key)); } catch (IOException e) { - return invalid("err.list.failed", "listing failed for prefix: "+key); + return invalid("err.list.failed", "listing failed for prefix: "+key, key); } } @@ -95,7 +98,7 @@ public class StorageResource { try { return ok(driver.listNext(thisNodeUuid(), id)); } catch (IOException e) { - return invalid("err.listNext.failed", "listing failed for id: "+id); + return invalid("err.listNext.failed", "listing failed for id: "+id, id); } } @@ -125,8 +128,8 @@ public class StorageResource { if (key.equals("*")) key = ""; try { return ok(getStorageDriver().get().delete(thisNodeUuid(), key)); - } catch (IOException e) { - return die("delete: "+e, e); + } catch (Exception e) { + return invalid("err.delete.failed", "delete operation failed for key: "+key+": "+shortError(e), key); } } diff --git a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties index 2f996f4b..e1982034 100644 --- a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties +++ b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties @@ -333,8 +333,6 @@ err.key.required=Key is required err.label.invalid=Label is invalid err.label.length=Label is too long err.latlon.invalid=lat/lon is invalid -err.list.failed=listing failed for prefix -err.listNext.failed=listing next batch failed for id err.name.invalid=Name is invalid err.name.regexFailed=Name must start with a letter and can only contain letters, numbers, hyphens, periods and underscores err.node.name.alreadyExists=A node already exists with the same FQDN @@ -450,7 +448,6 @@ err.user.exists=A user with this name already exists err.user.noContact=No contact information provided for user err.value.required=Value is required err.version.mismatch=Version in URL does not match version in object -err.write.failed=Write operation failed for key err.entity.classInFilename.invalid=Type of object could not be determined from filename. The part before the first dot or underscore should be a valid type name err.entity.filenameExtension.invalid=The object file must be a JSON file containing one or more objects, or a Model Archive File (ending in .zip, .tar.gz, or .tgz) containing a manifest and corresponding object files. err.entity.fileZipFormat.invalid=The Model Archive File was not in a readable format diff --git a/bubble-server/src/main/resources/message_templates/en_US/server/pre_auth/ResourceMessages.properties b/bubble-server/src/main/resources/message_templates/en_US/server/pre_auth/ResourceMessages.properties index d699527c..a589de37 100644 --- a/bubble-server/src/main/resources/message_templates/en_US/server/pre_auth/ResourceMessages.properties +++ b/bubble-server/src/main/resources/message_templates/en_US/server/pre_auth/ResourceMessages.properties @@ -148,6 +148,13 @@ err.storage.noneSpecified=No Storage service was configured err.compute.noneSpecified=No Compute service was configured err.cloud.localStorageIsReservedName=LocalStorage is a reserved name +# Storage driver errors +err.read.failed=read failed for key +err.list.failed=listing failed for prefix +err.listNext.failed=listing next batch failed for id +err.write.failed=Write operation failed for key +err.delete.failed=Delete operation failed for key + # Entity config errors err.ec.param.invalid=Parameter is invalid err.ec.fieldType.none_set=Field type was not set