diff --git a/src/main/java/io/sinistral/proteus/server/ServerResponse.java b/src/main/java/io/sinistral/proteus/server/ServerResponse.java index 152a33e..6e1d9d6 100644 --- a/src/main/java/io/sinistral/proteus/server/ServerResponse.java +++ b/src/main/java/io/sinistral/proteus/server/ServerResponse.java @@ -17,6 +17,7 @@ import io.sinistral.proteus.server.predicates.ServerPredicates; import io.undertow.io.IoCallback; +import io.undertow.server.DefaultResponseListener; import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.Cookie; @@ -357,33 +358,8 @@ else if (ServerPredicates.ACCEPT_XML_PREDICATE.resolve(exchange)) if (hasError) { - Map errorMap = new HashMap<>(); - - errorMap.put("message", throwable.getMessage()); - - if (throwable.getStackTrace() != null) - { - if (throwable.getStackTrace().length > 0) - { - errorMap.put("exceptionClass", throwable.getStackTrace()[0].getClassName()); - } - } - - if (this.processXml) - { - try - { - exchange.getResponseSender().send(ByteBuffer.wrap(XML_MAPPER.writeValueAsBytes(errorMap))); - } catch (JsonProcessingException e) - { - log.warn("Unable to create XML from error..."); - } - } - else - { - exchange.getResponseSender().send(JsonStream.serializeToBytes(errorMap, this.jsonContext)); - } - + exchange.putAttachment(DefaultResponseListener.EXCEPTION, throwable); + return; } diff --git a/src/main/java/io/sinistral/proteus/server/handlers/ServerDefaultResponseListener.java b/src/main/java/io/sinistral/proteus/server/handlers/ServerDefaultResponseListener.java index cb71753..651d69b 100644 --- a/src/main/java/io/sinistral/proteus/server/handlers/ServerDefaultResponseListener.java +++ b/src/main/java/io/sinistral/proteus/server/handlers/ServerDefaultResponseListener.java @@ -44,7 +44,7 @@ public boolean handleDefaultResponse(HttpServerExchange exchange) return false; } - if (exchange.getStatusCode() == 500) { + if (exchange.getStatusCode() >= 400) { Throwable throwable = exchange.getAttachment(DefaultResponseListener.EXCEPTION);