use of ch.qos.logback.classic.spi.ThrowableProxy in project spring-boot by spring-projects.
the class WhitespaceThrowableProxyConverterTests method withStackTrace.
@Test
public void withStackTrace() throws Exception {
this.event.setThrowableProxy(new ThrowableProxy(new RuntimeException()));
String s = this.converter.convert(this.event);
assertThat(s).startsWith(LINE_SEPARATOR).endsWith(LINE_SEPARATOR);
}
use of ch.qos.logback.classic.spi.ThrowableProxy in project spring-boot by spring-projects.
the class ExtendedWhitespaceThrowableProxyConverterTests method withStackTrace.
@Test
public void withStackTrace() throws Exception {
this.event.setThrowableProxy(new ThrowableProxy(new RuntimeException()));
String s = this.converter.convert(this.event);
assertThat(s).startsWith(LINE_SEPARATOR).endsWith(LINE_SEPARATOR);
}
use of ch.qos.logback.classic.spi.ThrowableProxy in project opentsdb by OpenTSDB.
the class HttpQuery method internalError.
/**
* Sends a 500 error page to the client.
* Handles responses from deprecated API calls as well as newer, versioned
* API calls
* @param cause The unexpected exception that caused this error.
*/
@Override
public void internalError(final Exception cause) {
logError("Internal Server Error on " + request().getUri(), cause);
if (this.api_version > 0) {
// need to return something
switch(this.api_version) {
case 1:
default:
sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, serializer.formatErrorV1(cause));
}
return;
}
ThrowableProxy tp = new ThrowableProxy(cause);
tp.calculatePackagingData();
final String pretty_exc = ThrowableProxyUtil.asString(tp);
tp = null;
if (hasQueryStringParam("json")) {
// 32 = 10 + some extra space as exceptions always have \t's to escape.
final StringBuilder buf = new StringBuilder(32 + pretty_exc.length());
buf.append("{\"err\":\"");
HttpQuery.escapeJson(pretty_exc, buf);
buf.append("\"}");
sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, buf);
} else {
sendReply(HttpResponseStatus.INTERNAL_SERVER_ERROR, makePage("Internal Server Error", "Houston, we have a problem", "<blockquote>" + "<h1>Internal Server Error</h1>" + "Oops, sorry but your request failed due to a" + " server error.<br/><br/>" + "Please try again in 30 seconds.<pre>" + pretty_exc + "</pre></blockquote>"));
}
}
use of ch.qos.logback.classic.spi.ThrowableProxy in project opentsdb by OpenTSDB.
the class HttpSerializer method formatErrorV1.
/**
* Format a bad request exception, indicating an invalid request from the
* user
* <p>
* <b>WARNING:</b> If overriding, make sure this method catches all errors and
* returns a byte array with a simple string error at the minimum
* @param exception The exception to format
* @return A standard JSON error
*/
public ChannelBuffer formatErrorV1(final BadRequestException exception) {
StringBuilder output = new StringBuilder(exception.getMessage().length() * 2);
final String jsonp = query.getQueryStringParam("jsonp");
if (jsonp != null && !jsonp.isEmpty()) {
output.append(query.getQueryStringParam("jsonp") + "(");
}
output.append("{\"error\":{\"code\":");
output.append(exception.getStatus().getCode());
final StringBuilder msg = new StringBuilder(exception.getMessage().length());
HttpQuery.escapeJson(exception.getMessage(), msg);
output.append(",\"message\":\"").append(msg.toString()).append("\"");
if (!exception.getDetails().isEmpty()) {
final StringBuilder details = new StringBuilder(exception.getDetails().length());
HttpQuery.escapeJson(exception.getDetails(), details);
output.append(",\"details\":\"").append(details.toString()).append("\"");
}
if (query.showStackTrace()) {
ThrowableProxy tp = new ThrowableProxy(exception);
tp.calculatePackagingData();
final String pretty_exc = ThrowableProxyUtil.asString(tp);
final StringBuilder trace = new StringBuilder(pretty_exc.length());
HttpQuery.escapeJson(pretty_exc, trace);
output.append(",\"trace\":\"").append(trace.toString()).append("\"");
}
output.append("}}");
if (jsonp != null && !jsonp.isEmpty()) {
output.append(")");
}
return ChannelBuffers.copiedBuffer(output.toString().getBytes(this.query.getCharset()));
}
use of ch.qos.logback.classic.spi.ThrowableProxy in project opentsdb by OpenTSDB.
the class HttpSerializer method formatErrorV1.
/**
* Format an internal error exception that was caused by the system
* Should return a 500 error
* <p>
* <b>WARNING:</b> If overriding, make sure this method catches all errors and
* returns a byte array with a simple string error at the minimum
* @param exception The system exception to format
* @return A standard JSON error
*/
public ChannelBuffer formatErrorV1(final Exception exception) {
String message = exception.getMessage();
// NPEs have a null for the message string (why?!?!?!)
if (exception.getClass() == NullPointerException.class) {
message = "An internal null pointer exception was thrown";
} else if (message == null) {
message = "An unknown exception occurred";
}
StringBuilder output = new StringBuilder(message.length() * 2);
final String jsonp = query.getQueryStringParam("jsonp");
if (jsonp != null && !jsonp.isEmpty()) {
output.append(query.getQueryStringParam("jsonp") + "(");
}
output.append("{\"error\":{\"code\":");
output.append(500);
final StringBuilder msg = new StringBuilder(message.length());
HttpQuery.escapeJson(message, msg);
output.append(",\"message\":\"").append(msg.toString()).append("\"");
if (query.showStackTrace()) {
ThrowableProxy tp = new ThrowableProxy(exception);
tp.calculatePackagingData();
final String pretty_exc = ThrowableProxyUtil.asString(tp);
final StringBuilder trace = new StringBuilder(pretty_exc.length());
HttpQuery.escapeJson(pretty_exc, trace);
output.append(",\"trace\":\"").append(trace.toString()).append("\"");
}
output.append("}}");
if (jsonp != null && !jsonp.isEmpty()) {
output.append(")");
}
return ChannelBuffers.copiedBuffer(output.toString().getBytes(this.query.getCharset()));
}
Aggregations