Skip to content

Commit

Permalink
Clean up error handling in ServerResponse.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed May 23, 2017
1 parent ec4fc90 commit 94ece22
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
30 changes: 3 additions & 27 deletions src/main/java/io/sinistral/proteus/server/ServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -357,33 +358,8 @@ else if (ServerPredicates.ACCEPT_XML_PREDICATE.resolve(exchange))

if (hasError)
{
Map<String, String> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 94ece22

Please sign in to comment.