disable error trace by deault, enable it using rest param called errorTrace which can be set to 1/true/on

This commit is contained in:
kimchy 2010-02-19 09:55:02 +02:00
parent 2a3fcce818
commit bfc5ad7b92
2 changed files with 17 additions and 15 deletions

View File

@ -133,7 +133,7 @@ public class NettyHttpRequest implements HttpRequest {
if (sValue == null) {
return defaultValue;
}
return sValue.equals("true") || sValue.equals("1");
return sValue.equals("true") || sValue.equals("1") || sValue.equals("on");
}
@Override public TimeValue paramAsTime(String key, TimeValue defaultValue) {

View File

@ -52,30 +52,32 @@ public class JsonThrowableRestResponse extends JsonRestResponse {
}
public JsonThrowableRestResponse(RestRequest request, Status status, Throwable t) throws IOException {
super(request, status, convert(t));
super(request, status, convert(request, t));
}
private static JsonBuilder convert(Throwable t) throws IOException {
private static JsonBuilder convert(RestRequest request, Throwable t) throws IOException {
Holder holder = cache.get();
holder.writer.reset();
t.printStackTrace(holder.printWriter);
JsonBuilder builder = jsonBuilder().prettyPrint()
.startObject().field("error", ExceptionsHelper.detailedMessage(t, false, 0));
builder.startObject("debug");
boolean first = true;
while (t != null) {
if (!first) {
builder.startObject("cause");
if (request.paramAsBoolean("errorTrace", false)) {
builder.startObject("errorTrace");
boolean first = true;
while (t != null) {
if (!first) {
builder.startObject("cause");
}
buildThrowable(t, builder);
if (!first) {
builder.endObject();
}
t = t.getCause();
first = false;
}
buildThrowable(t, builder);
if (!first) {
builder.endObject();
}
t = t.getCause();
first = false;
builder.endObject();
}
builder.endObject();
builder.endObject();
return builder;
}