Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log useful exceptions instead of swallowing them #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public String getPath() {
try {
return getPathForEntity();
} catch (Exception e) {
throw new CommandException("Unable to encode the object path");
throw new CommandException("Unable to encode the object path", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static String getPath(String url) {
try {
return new URL(url).getPath();
} catch (MalformedURLException e) {
throw new CommandException("Unable to parse URL "+url);
throw new CommandException("Unable to parse URL "+url, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void configureHttpClientBuilder(HttpClientBuilder clientBuilder) {
}
clientBuilder.setProxy(createProxy());
} catch (Exception e) {
LOG.error("JOSS / Invalid proxy authorization settings");
LOG.error("JOSS / Invalid proxy authorization settings", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public N call() {
throw err;
} catch (IOException err) {
request.releaseConnection();
throw new CommandException("Unable to execute the HTTP call or to convert the HTTP Response", err);
throw new CommandException("Unable to execute the HTTP call or to convert the HTTP Response. Request URI: " + request.getURI(), err);
} finally {
if (closeStreamAutomatically()) {
try { close(); } catch (IOException err) { /* ignore */ }
try { close(); } catch (IOException err) {
LOG.warn("Failed to close response. Request URI: " + request.getURI(), err);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public N call() {
return super.call();
} catch (UnauthorizedException err) {
if (account.isAllowReauthenticate()) {
LOG.info("Attempting to re-authenticate due to authorization failure " + err.getMessage());
Access access = account.authenticate();
if (account.getPreferredRegion() != null) {
access.setPreferredRegion(account.getPreferredRegion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static ObjectLastModified fromResponse(HttpResponse response) {
try {
return new ObjectLastModified(convertResponseHeader(response, LAST_MODIFIED));
} catch (DateParseException e) {
throw new CommandException("Unable to convert date string");
throw new CommandException("Unable to convert date string", e);
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/javaswift/joss/swift/Swift.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.javaswift.joss.swift.scheduled.ObjectDeleter;
import org.javaswift.joss.swift.statusgenerator.StatusGenerator;
import org.javaswift.joss.util.LocalTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.io.File;
Expand All @@ -31,6 +33,8 @@
*/
public class Swift {

public static final Logger LOG = LoggerFactory.getLogger(Swift.class);

private Map<String, SwiftContainer> containers = new TreeMap<String, SwiftContainer>();

private boolean allowObjectDeleter;
Expand Down Expand Up @@ -443,6 +447,7 @@ public SwiftResult<Object> downloadObject(Container container, StoredObject obje
os = new FileOutputStream(targetFile);
IOUtils.copy(is, os);
} catch (IOException err) {
LOG.error("Failed when downloading object", err);
return new SwiftResult<Object>(HttpStatus.SC_UNPROCESSABLE_ENTITY);
} finally {
closeStreams(is, os);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/javaswift/joss/swift/SwiftStoredObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
import org.javaswift.joss.instructions.UploadInstructions;
import org.javaswift.joss.model.*;
import org.javaswift.joss.util.LocalTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.activation.MimetypesFileTypeMap;
import java.io.IOException;
import java.util.*;

public class SwiftStoredObject implements ListSubject, DirectoryOrObject {

public static final Logger LOG = LoggerFactory.getLogger(Swift.class);

private String name;

private byte[] content;
Expand Down Expand Up @@ -87,6 +91,7 @@ public SwiftResult<Object> uploadObject(UploadInstructions uploadInstructions) {
new ObjectContentType(new MimetypesFileTypeMap().getContentType(getName()));
return new SwiftResult<Object>(HttpStatus.SC_CREATED);
} catch (IOException err) {
LOG.error("Failed when uploading object", err);
return new SwiftResult<Object>(HttpStatus.SC_UNPROCESSABLE_ENTITY);
}
}
Expand Down