Example usage for io.netty.util.internal ThrowableUtil stackTraceToString

List of usage examples for io.netty.util.internal ThrowableUtil stackTraceToString

Introduction

In this page you can find the example usage for io.netty.util.internal ThrowableUtil stackTraceToString.

Prototype

public static String stackTraceToString(Throwable cause) 

Source Link

Document

Gets the stack trace from a Throwable as a String.

Usage

From source file:org.restnext.server.ServerHandler.java

License:Apache License

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    if (ctx.channel().isActive()) {
        // Create the response status error.
        Response.Status status = cause instanceof ServerException
                ? ((ServerException) cause).getResponseStatus()
                : INTERNAL_SERVER_ERROR;

        // Create the response error body.
        String newLine = "\r\n";
        StringJoiner content = new StringJoiner(newLine);
        content.add("statusCode: " + status.getStatusCode());
        content.add("statusMessage: " + status.getReasonPhrase());
        content.add("statusFamily: " + status.getFamily());
        if (cause.getMessage() != null) {
            content.add("errorMessage: " + cause.getMessage());
        }/*from  w w  w .  jav a 2s .  c  om*/
        if (cause.getCause() != null) {
            content.add("detailErrorMessage: " + cause.getCause().getMessage());
        }
        content.add("stackTraceMessage: " + ThrowableUtil.stackTraceToString(cause));

        // Write the response error.
        write(ctx, Response.status(status).content(content.toString()).type(MediaType.TEXT_UTF8).build(),
                false);
    }
    ctx.close();
}