Search in sources :

Example 1 with UnexpectedResponseExceptionType

use of com.azure.android.core.rest.annotation.UnexpectedResponseExceptionType 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);
}
Also used : UnexpectedResponseExceptionType(com.azure.android.core.rest.annotation.UnexpectedResponseExceptionType) HashMap(java.util.HashMap) UnexpectedResponseExceptionTypes(com.azure.android.core.rest.annotation.UnexpectedResponseExceptionTypes) HttpResponseExceptionInfo(com.azure.android.core.rest.implementation.HttpResponseExceptionInfo) HttpResponseException(com.azure.android.core.http.exception.HttpResponseException)

Aggregations

HttpResponseException (com.azure.android.core.http.exception.HttpResponseException)1 UnexpectedResponseExceptionType (com.azure.android.core.rest.annotation.UnexpectedResponseExceptionType)1 UnexpectedResponseExceptionTypes (com.azure.android.core.rest.annotation.UnexpectedResponseExceptionTypes)1 HttpResponseExceptionInfo (com.azure.android.core.rest.implementation.HttpResponseExceptionInfo)1 HashMap (java.util.HashMap)1