close(originalInputStream, true);
}
}
// Process the payload and look for errors
BaseResponse responseContent = errorParser.apply(in);
if (responseContent != null && responseContent.getStatus() == Status.ERROR) {
// Yes, this is ugly, but the DigitalOcean API sometimes sets the status code to 200 for these errors and
// the only way to know what happened is parsing the error message
String message = responseContent.getMessage();
if (ACCESS_DENIED.equals(message)) {
response.statusCode(401);
} else if (NOT_FOUND.equals(message)) {
response.statusCode(404);
} else {
response.statusCode(500);
}
response.message(responseContent.getDetails());
}
// Reset the input stream and set the payload, so it can be read again
// by the response and error parsers
in.reset();