use of com.aliyun.oss.common.parser.JAXBResponseParser in project aliyun-oss-java-sdk by aliyun.
the class OSSErrorResponseHandler method handle.
public void handle(ResponseMessage response) throws OSSException, ClientException {
if (response.isSuccessful()) {
return;
}
String requestId = response.getRequestId();
int statusCode = response.getStatusCode();
if (response.getContent() == null) {
/**
* When HTTP response body is null, handle status code 404 Not
* Found, 304 Not Modified, 412 Precondition Failed especially.
*/
if (statusCode == HttpStatus.SC_NOT_FOUND) {
throw ExceptionFactory.createOSSException(requestId, OSSErrorCode.NO_SUCH_KEY, "Not Found");
} else if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
throw ExceptionFactory.createOSSException(requestId, OSSErrorCode.NOT_MODIFIED, "Not Modified");
} else if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) {
throw ExceptionFactory.createOSSException(requestId, OSSErrorCode.PRECONDITION_FAILED, "Precondition Failed");
} else {
throw ExceptionFactory.createUnknownOSSException(requestId, statusCode);
}
}
JAXBResponseParser parser = new JAXBResponseParser(OSSErrorResult.class);
try {
OSSErrorResult errorResult = (OSSErrorResult) parser.parse(response);
throw ExceptionFactory.createOSSException(errorResult, response.getErrorResponseAsString());
} catch (ResponseParseException e) {
throw ExceptionFactory.createInvalidResponseException(requestId, response.getErrorResponseAsString(), e);
} finally {
safeCloseResponse(response);
}
}
Aggregations