You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/04/11 08:34:01 UTC
[camel] 01/02: (chores) camel-box: cleanup of duplicated code for exception handling
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ea6d216341bc2dc31cfe4ef54daf451294b54ca4
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Apr 11 09:14:30 2023 +0200
(chores) camel-box: cleanup of duplicated code for exception handling
---
.../camel/component/box/api/BoxFilesManager.java | 68 +++++++++-------------
1 file changed, 27 insertions(+), 41 deletions(-)
diff --git a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxFilesManager.java b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxFilesManager.java
index e019fa7afdf..cc188daad22 100644
--- a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxFilesManager.java
+++ b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxFilesManager.java
@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
*/
public class BoxFilesManager {
+ public static final String BASE_ERROR_MESSAGE = "Box API returned the error code %d%n%n%s";
private static final Logger LOG = LoggerFactory.getLogger(BoxFilesManager.class);
/**
@@ -82,8 +83,7 @@ public class BoxFilesManager {
return file.getInfo(fields);
}
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -108,7 +108,7 @@ public class BoxFilesManager {
return file;
} catch (BoxAPIException e) {
throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ buildErrorMessage(e), e);
}
}
@@ -219,7 +219,7 @@ public class BoxFilesManager {
return boxFile;
} catch (BoxAPIException e) {
throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ buildErrorMessage(e), e);
}
}
@@ -259,8 +259,7 @@ public class BoxFilesManager {
return file;
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -283,10 +282,14 @@ public class BoxFilesManager {
} catch (BoxAPIException e) {
throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ buildErrorMessage(e), e);
}
}
+ private static String buildErrorMessage(BoxAPIException e) {
+ return String.format(BASE_ERROR_MESSAGE, e.getResponseCode(), e.getResponse());
+ }
+
/**
* Download a file.
*
@@ -328,8 +331,7 @@ public class BoxFilesManager {
}
return output;
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -370,8 +372,7 @@ public class BoxFilesManager {
}
return output;
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -400,8 +401,7 @@ public class BoxFilesManager {
fileVersion.promote();
return fileVersion;
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -433,8 +433,7 @@ public class BoxFilesManager {
return fileToCopy.copy(destinationFolder, newName).getResource();
}
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -466,8 +465,7 @@ public class BoxFilesManager {
return (BoxFile) fileToMove.move(destinationFolder, newName).getResource();
}
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -491,8 +489,7 @@ public class BoxFilesManager {
fileToRename.rename(newFileName);
return fileToRename;
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -510,8 +507,7 @@ public class BoxFilesManager {
BoxFile file = new BoxFile(boxConnection, fileId);
file.delete();
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -538,8 +534,7 @@ public class BoxFilesManager {
fileVersion.delete();
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -574,8 +569,7 @@ public class BoxFilesManager {
BoxFile file = new BoxFile(boxConnection, fileId);
return file.createSharedLink(access, unshareDate, permissions);
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -598,8 +592,7 @@ public class BoxFilesManager {
return file.getDownloadURL();
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -621,8 +614,7 @@ public class BoxFilesManager {
BoxFile file = new BoxFile(boxConnection, fileId);
return file.getPreviewLink();
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -668,8 +660,7 @@ public class BoxFilesManager {
BoxFile file = new BoxFile(boxConnection, fileId);
return file.getThumbnail(fileType, minWidth, minHeight, maxWidth, maxHeight);
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -701,8 +692,7 @@ public class BoxFilesManager {
return file.createMetadata(metadata);
}
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -730,8 +720,7 @@ public class BoxFilesManager {
return file.getMetadata();
}
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -755,8 +744,7 @@ public class BoxFilesManager {
BoxFile file = new BoxFile(boxConnection, fileId);
return file.updateMetadata(metadata);
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -774,8 +762,7 @@ public class BoxFilesManager {
BoxFile file = new BoxFile(boxConnection, fileId);
file.deleteMetadata();
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
@@ -804,8 +791,7 @@ public class BoxFilesManager {
BoxFolder parentFolder = new BoxFolder(boxConnection, parentFolderId);
parentFolder.canUpload(fileName, size);
} catch (BoxAPIException e) {
- throw new RuntimeCamelException(
- String.format("Box API returned the error code %d%n%n%s", e.getResponseCode(), e.getResponse()), e);
+ throw new RuntimeCamelException(buildErrorMessage(e), e);
}
}
}