private static <T> void fillExceptionWithData(final SphereRequest<T> sphereRequest, final HttpResponse httpResponse, final SphereException exception, final SphereApiConfig config) { exception.setSphereRequest(sphereRequest); exception.setUnderlyingHttpResponse(httpResponse); exception.setProjectKey(config.getProjectKey()); final List<String> errorMessagesDueToMappingError = asList("SearchPhaseExecutionException", "query_fetch", "RemoteTransportException", "SearchParseException", "search/phase/query+fetch"); Optional.ofNullable(httpResponse.getResponseBody()) .map(bytes -> bytesToString(bytes)) .map(body -> errorMessagesDueToMappingError.stream().anyMatch(errorWord -> body.contains(errorWord)) && body.toLowerCase().contains("product")) .ifPresent(containsTerm -> { if (containsTerm) { exception.addNote(format("Maybe it helps to reindex the products https://admin.sphere.io/%s/developers/danger but this may take a while.", config.getProjectKey())); } }); }
@Override public Function<HttpResponse, T> resultMapper() { return response -> { final List<String> deprecationNoticeHeaderValues = getDeprecationNoticeHeaderValues(response); if (deprecationNoticeHeaderValues.isEmpty()) { return sphereRequest.resultMapper().apply(response); } else { final SphereException sphereException = new SphereDeprecationException(deprecationNoticeHeaderValues); sphereException.setSphereRequest(sphereRequest); sphereException.setUnderlyingHttpResponse(response); throw sphereException; } }; }
@Override public T deserialize(final HttpResponse httpResponse) { final List<String> deprecationNoticeHeaderValues = getDeprecationNoticeHeaderValues(httpResponse); if (deprecationNoticeHeaderValues.isEmpty()) { return sphereRequest.deserialize(httpResponse); } else { final SphereException sphereException = new SphereDeprecationException(deprecationNoticeHeaderValues); sphereException.setSphereRequest(sphereRequest); sphereException.setUnderlyingHttpResponse(httpResponse); throw sphereException; } }
@Override public T deserialize(final HttpResponse httpResponse) { final List<String> deprecationNoticeHeaderValues = getDeprecationNoticeHeaderValues(httpResponse); if (deprecationNoticeHeaderValues.isEmpty()) { return sphereRequest.deserialize(httpResponse); } else { final SphereException sphereException = new SphereDeprecationException(deprecationNoticeHeaderValues); sphereException.setSphereRequest(sphereRequest); sphereException.setUnderlyingHttpResponse(httpResponse); throw sphereException; } }
private static <T> void fillExceptionWithData(final SphereRequest<T> sphereRequest, final HttpResponse httpResponse, final SphereException exception, final SphereApiConfig config) { exception.setSphereRequest(sphereRequest); exception.setUnderlyingHttpResponse(httpResponse); exception.setProjectKey(config.getProjectKey()); }
@Override public T deserialize(final HttpResponse httpResponse) { final List<String> deprecationNoticeHeaderValues = getDeprecationNoticeHeaderValues(httpResponse); if (deprecationNoticeHeaderValues.isEmpty()) { return sphereRequest.deserialize(httpResponse); } else { final SphereException sphereException = new SphereDeprecationException(deprecationNoticeHeaderValues); sphereException.setSphereRequest(sphereRequest); sphereException.setUnderlyingHttpResponse(httpResponse); throw sphereException; } }
private static <T> void fillExceptionWithData(final SphereRequest<T> sphereRequest, final HttpResponse httpResponse, final SphereException exception, final SphereApiConfig config, final HttpRequest httpRequest) { exception.setSphereRequest(sphereRequest); exception.setUnderlyingHttpResponse(httpResponse); exception.setProjectKey(config.getProjectKey()); exception.setHttpRequest(httpRequest); }
private static <T> void fillExceptionWithData(final SphereRequest<T> sphereRequest, final HttpResponse httpResponse, final SphereException exception, final SphereApiConfig config, final HttpRequest httpRequest) { exception.setSphereRequest(sphereRequest); exception.setUnderlyingHttpResponse(httpResponse); exception.setProjectKey(config.getProjectKey()); exception.setHttpRequest(httpRequest); }