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())); } }); }