/** * Get whether or not the provided response status code is one of the expected status codes for * this Swagger method. * @param responseStatusCode The status code that was returned in the HTTP response. * @return whether or not the provided response status code is one of the expected status codes * for this Swagger method. */ public boolean isExpectedResponseStatusCode(int responseStatusCode) { return isExpectedResponseStatusCode(responseStatusCode, null); }
/** * Ensure that the provided HttpResponse has a status code that is defined in the provided * SwaggerMethodParser or is in the int[] of additional allowed status codes. If the * HttpResponse's status code is not allowed, then an exception will be thrown. * @param response The HttpResponse to check. * @param methodParser The method parser that contains information about the service interface * method that initiated the HTTP request. * @param additionalAllowedStatusCodes Additional allowed status codes that are permitted based * on the context of the HTTP request. * @return An async-version of the provided HttpResponse. */ public Single<HttpResponse> ensureExpectedStatus(final HttpResponse response, final SwaggerMethodParser methodParser, int[] additionalAllowedStatusCodes) { final int responseStatusCode = response.statusCode(); final Single<HttpResponse> asyncResult; if (!methodParser.isExpectedResponseStatusCode(responseStatusCode, additionalAllowedStatusCodes)) { asyncResult = response.bodyAsString().flatMap(new Function<String, Single<HttpResponse>>() { @Override public Single<HttpResponse> apply(String responseBody) throws Exception { return Single.error(instantiateUnexpectedException(methodParser, response, responseBody)); } }); } else { asyncResult = Single.just(response); } return asyncResult; }