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

exception_support_return_header #88

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
14 changes: 14 additions & 0 deletions src/main/java/com/qcloud/cos/exception/CosServiceException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.qcloud.cos.exception;

import java.util.HashMap;
import java.util.Map;

/**
Expand Down Expand Up @@ -102,6 +103,11 @@ public enum ErrorType {
*/
private Map<String, String> additionalDetails;

/**
* header information
*/
private Map<String, String> headers = new HashMap<String, String>();

/**
* Returns the error XML received in the HTTP Response or null if the exception is constructed
* from the headers.
Expand Down Expand Up @@ -290,5 +296,13 @@ public void setRawResponseContent(String rawResponseContent) {
this.rawResponseContent = rawResponseContent;
}

public Map<String, String> getHeaders() {
return headers;
}

public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class CosServiceExceptionBuilder {
*/
private Map<String, String> additionalDetails;

/**
* header information
*/
private Map<String, String> headers = new HashMap<String, String>();

/**
* Returns the error XML received in the HTTP Response or null if the exception is constructed
* from the headers.
Expand Down Expand Up @@ -185,6 +190,7 @@ public CosServiceException build() {
cosException.setRequestId(requestId);
cosException.setAdditionalDetails(additionalDetails);
cosException.setErrorType(errorTypeOf(statusCode));
cosException.setHeaders(headers);
return cosException;
}

Expand All @@ -198,4 +204,13 @@ public CosServiceException build() {
private ErrorType errorTypeOf(int statusCode) {
return statusCode >= 500 ? ErrorType.Service : ErrorType.Client;
}

public Map<String, String> getHeaders() {
return headers;
}

public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public CosServiceException handle(CosHttpResponse httpResponse) throws XMLStream
*/
int targetDepth = 0;
final CosServiceExceptionBuilder exceptionBuilder = new CosServiceExceptionBuilder();
exceptionBuilder.setHeaders(httpResponse.getHeaders());
exceptionBuilder.setErrorResponseXml(content);
exceptionBuilder.setStatusCode(httpResponse.getStatusCode());

Expand Down