private String responseBodyFormatted() { try { return Optional.ofNullable(getHttpResponse()) .map(r -> r.getResponseBody()) .map(b -> SphereJsonUtils.prettyPrint(new String(b, StandardCharsets.UTF_8))) .map(s -> "http response formatted body: " + s + "\n") .orElse(""); } catch (final Exception e) { return ""; } }
@Override public final String getMessage() { StringBuilder builder = new StringBuilder("\n===== BEGIN EXCEPTION OUTPUT =====").append("\n"); final String httpRequest = getSphereRequest().map(x -> x.httpRequestIntent()).map(Object::toString).orElse("<unknown>"); return builder .append("SDK: ").append(BuildInfo.version()).append("\n") .append("project: ").append(getProjectKey().orElse("<unknown>")).append("\n") .append(getSphereRequest().map(x -> x.httpRequestIntent()).map(x -> "" + x.getHttpMethod() + " " + x.getPath()).map(x -> "endpoint: " + x + "\n").orElse("")) .append("Java: ").append(System.getProperty("java.version")).append("\n") .append("cwd: ").append(System.getProperty("user.dir")).append("\n") .append("date: ").append(new Date()).append("\n") .append("sphere request: ").append(getSphereRequest().map(Object::toString).orElse("<unknown>")).append("\n") //duplicated in case SphereRequest does not implement a proper to String .append("http request: ").append(httpRequest).append("\n") .append("http response: ").append(getHttpResponse().map(Object::toString).orElse("<unknown>")).append("\n") .append(Optional.ofNullable(super.getMessage()).map(s -> "detailMessage: " + s + "\n").orElse("")) .append("additional notes: ").append(additionalNotes).append("\n") .append("Javadoc: ").append("http://sphereio.github.io/sphere-jvm-sdk/javadoc/").append(BuildInfo.version()).append("/").append(this.getClass().getCanonicalName().replace('.', '/')).append(".html").append("\n") .append("===== END EXCEPTION OUTPUT =====").toString(); }
@Override public final String getMessage() { StringBuilder builder = new StringBuilder(); return builder .append(Optional.ofNullable(super.getMessage()).map(s -> "detailMessage: " + s + "\n").orElse("")) .append(httpSummary()) .append(responseBodyFormatted()) .append("http response: ").append(Optional.ofNullable(getHttpResponse()).map(Object::toString).orElse("<unknown>")).append("\n") .append("SDK: ").append(BuildInfo.version()).append("\n") .append("project: ").append(Optional.ofNullable(getProjectKey()).orElse("<unknown>")).append("\n") .append(Optional.ofNullable(getSphereRequest()).map(x -> x.httpRequestIntent()).map(x -> "" + x.getHttpMethod() + " " + x.getPath()).map(x -> "endpoint: " + x + "\n").orElse("")) .append("Java: ").append(System.getProperty("java.version")).append("\n") .append("cwd: ").append(System.getProperty("user.dir")).append("\n") .append("sphere request: ").append(Optional.ofNullable(getSphereRequest()).map(Object::toString).orElse("<unknown>")).append("\n") //duplicated in case SphereRequest does not implement a proper to String .append(httpRequestLine()) .append(requestBodyFormatted()) .append("additional notes: ").append(additionalNotes).append("\n") .append("Javadoc: ").append("http://commercetools.github.io/commercetools-jvm-sdk/apidocs/").append(this.getClass().getCanonicalName().replace('.', '/')).append(".html").append("\n") .toString(); }