package com.voodoodyne.gstrap.rest;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.voodoodyne.gstrap.lang.Types;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
 * JSON structure of an error body from the ThrowableMapper
 */
@RequiredArgsConstructor
public class ErrorBody {
	private final Throwable t;

	public String getMessage() {
		return t.getMessage();
	}

	public String getType() {
		return t.getClass().getSimpleName();
	}

	public List<String> getTypes() {
		return Types.getTypes(t, ClientException.class, RuntimeException.class, Exception.class, Throwable.class);
	}

	public ErrorBody getCause() {
		return t.getCause() == null ? null : new ErrorBody(t.getCause());
	}

	@JsonUnwrapped
	public Object getAdditionalProperties() {
		if (t instanceof AdditionalProperties) {
			return ((AdditionalProperties)t).getAdditionalProperties();
		} else {
			return null;
		}
	}
}

@@ -188,16 +188,52 @@
 il.List;
+%0Aimport java.util.stream.Collectors;
 %0A%0A/**%0A *
@@ -344,16 +344,250 @@
 rBody %7B%0A
+%09private static final String stripExceptionSuffix(final String className) %7B%0A%09%09if (className.endsWith(%22Exception%22)) %7B%0A%09%09%09return className.substring(0, className.length() - %22Exception%22.length());%0A%09%09%7D else %7B%0A%09%09%09return className;%0A%09%09%7D%0A%09%7D%0A%0A
 %09private
@@ -698,24 +698,45 @@
  %7B%0A%09%09return 
+stripExceptionSuffix(
 t.getClass()
@@ -751,16 +751,17 @@
 leName()
+)
 ;%0A%09%7D%0A%0A%09p
@@ -899,16 +899,101 @@
 e.class)
+%0A%09%09%09%09.stream()%0A%09%09%09%09.map(ErrorBody::stripExceptionSuffix).collect(Collectors.toList())
 ;%0A%09%7D%0A%0A%09p

Remove "Exception" from the error text