use of com.azure.android.core.rest.annotation.UnexpectedResponseExceptionTypes 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