use of com.azure.android.core.rest.implementation.HttpResponseExceptionInfo in project azure-sdk-for-android by Azure.
the class HttpResponseMapper method map.
Response<?> map(HttpResponse httpResponse, JacksonSerder jacksonSerder) throws Throwable {
if (!isExpectedStatusCode(httpResponse.getStatusCode())) {
final HttpResponseExceptionInfo exceptionInfo = getExceptionInfo(httpResponse.getStatusCode());
throw logger.logThrowableAsError((exceptionInfo.instantiateException(jacksonSerder, httpResponse, logger)));
} else {
Object headerObject = null;
if (this.headerDecodeType != null) {
try {
headerObject = jacksonSerder.deserialize(httpResponse.getHeaders().toMap(), headerDecodeType);
} catch (IOException ioe) {
throw logger.logExceptionAsError(new HttpResponseException("HTTP response has malformed headers", httpResponse, ioe));
}
}
if (isBooleanResponseForHead(httpResponse)) {
final boolean isSuccess = (httpResponse.getStatusCode() / 100) == 2;
httpResponse.close();
return instantiateResponse(this.responseCtr, this.responseCtrParamCount, httpResponse.getRequest(), httpResponse, headerObject, isSuccess);
} else if (TypeUtil.isTypeOrSubTypeOf(this.contentDecodeType, Void.class)) {
httpResponse.close();
return instantiateResponse(this.responseCtr, this.responseCtrParamCount, httpResponse.getRequest(), httpResponse, headerObject, null);
} else if (TypeUtil.isTypeOrSubTypeOf(this.contentDecodeType, InputStream.class)) {
return instantiateResponse(this.responseCtr, this.responseCtrParamCount, httpResponse.getRequest(), httpResponse, headerObject, httpResponse.getBody());
} else if (TypeUtil.isTypeOrSubTypeOf(this.contentDecodeType, byte[].class)) {
if (this.contentEncodedType == Base64Url.class) {
final byte[] encodedContent = httpResponse.getBodyAsByteArray();
final byte[] decodedContent = new Base64Url(encodedContent).decodedBytes();
return instantiateResponse(this.responseCtr, this.responseCtrParamCount, httpResponse.getRequest(), httpResponse, headerObject, decodedContent);
} else {
return instantiateResponse(this.responseCtr, this.responseCtrParamCount, httpResponse.getRequest(), httpResponse, headerObject, httpResponse.getBodyAsByteArray());
}
} else if (this.contentEncodedType == null) {
final Object decodedContent = deserializeHttpBody(jacksonSerder, httpResponse, this.contentDecodeType);
return instantiateResponse(this.responseCtr, this.responseCtrParamCount, httpResponse.getRequest(), httpResponse, headerObject, decodedContent);
} else {
Objects.requireNonNull(this.contentEncodedType);
if (TypeUtil.isTypeOrSubTypeOf(this.contentEncodedType, Page.class)) {
final Type pageType = (this.contentEncodedType == Page.class) ? TypeUtil.createParameterizedType(ItemPage.class, this.contentDecodeType) : this.contentEncodedType;
final Object decodedContent = deserializeHttpBody(jacksonSerder, httpResponse, pageType);
return instantiateResponse(this.responseCtr, this.responseCtrParamCount, httpResponse.getRequest(), httpResponse, headerObject, decodedContent);
} else {
Objects.requireNonNull(this.expandedContentEncodedType);
final Object encodedContent = deserializeHttpBody(jacksonSerder, httpResponse, this.expandedContentEncodedType);
final Object decodedContent = decodeContent(encodedContent, this.contentEncodedType, this.contentDecodeType);
return instantiateResponse(this.responseCtr, this.responseCtrParamCount, httpResponse.getRequest(), httpResponse, headerObject, decodedContent);
}
}
}
}
use of com.azure.android.core.rest.implementation.HttpResponseExceptionInfo in project azure-sdk-for-android by Azure.
the class HttpResponseMapper method extractDefaultAndKnownExceptions.
private Pair<HttpResponseExceptionInfo, Map<Integer, HttpResponseExceptionInfo>> extractDefaultAndKnownExceptions(Method swaggerMethod) {
final UnexpectedResponseExceptionTypes unexpectedResponseExceptionTypesHolder = swaggerMethod.getAnnotation(UnexpectedResponseExceptionTypes.class);
if (unexpectedResponseExceptionTypesHolder == null || unexpectedResponseExceptionTypesHolder.value() == null || unexpectedResponseExceptionTypesHolder.value().length == 0) {
return Pair.create(new HttpResponseExceptionInfo(HttpResponseException.class), null);
}
final UnexpectedResponseExceptionType[] unexpectedResponseExceptionTypes = unexpectedResponseExceptionTypesHolder.value();
Map<Integer, HttpResponseExceptionInfo> statusCodeToKnownExceptionInfo = new HashMap<>(unexpectedResponseExceptionTypes.length);
HttpResponseExceptionInfo defaultExceptionInfo = null;
for (UnexpectedResponseExceptionType exceptionAnnotation : unexpectedResponseExceptionTypes) {
if (exceptionAnnotation.code().length == 0) {
defaultExceptionInfo = new HttpResponseExceptionInfo(exceptionAnnotation.value());
} else {
final HttpResponseExceptionInfo knownExceptionInfo = new HttpResponseExceptionInfo(exceptionAnnotation.value());
for (int statusCode : exceptionAnnotation.code()) {
statusCodeToKnownExceptionInfo.put(statusCode, knownExceptionInfo);
}
}
}
if (defaultExceptionInfo == null) {
defaultExceptionInfo = new HttpResponseExceptionInfo(HttpResponseException.class);
}
return Pair.create(defaultExceptionInfo, statusCodeToKnownExceptionInfo);
}
Aggregations