Error handler check for empty payload

This commit is contained in:
Andrew Donald Kennedy 2012-04-11 13:05:04 +01:00
parent b786178a90
commit fd616ddbed
1 changed files with 3 additions and 2 deletions

View File

@ -55,11 +55,12 @@ public class VCloudDirectorErrorHandler implements HttpErrorHandler {
: String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine()); : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine());
Exception exception = new HttpResponseException(command, response, message); Exception exception = new HttpResponseException(command, response, message);
// Try to create a VCloudDirectorException from XML payload // Try to create a VCloudDirectorException from XML payload, if it exists
if (response.getPayload().getContentMetadata().getContentType().startsWith(VCloudDirectorMediaType.ERROR)) { if (response.getPayload() != null && response.getPayload().getContentMetadata().getContentType().startsWith(VCloudDirectorMediaType.ERROR)) {
try { try {
Error error = JAXB.unmarshal(InputSuppliers.of(data).getInput(), Error.class); Error error = JAXB.unmarshal(InputSuppliers.of(data).getInput(), Error.class);
exception = new VCloudDirectorException(error); exception = new VCloudDirectorException(error);
message = error.getMessage();
} catch (Exception e) { } catch (Exception e) {
Throwables.propagate(e); Throwables.propagate(e);
} }