コード例 #1
0
 /**
  * Statis toXContent helper method that also renders non {@link
  * org.elasticsearch.ElasticsearchException} instances as XContent.
  */
 public static void toXContent(XContentBuilder builder, Params params, Throwable ex)
     throws IOException {
   ex = ExceptionsHelper.unwrapCause(ex);
   if (ex instanceof ElasticsearchException) {
     ((ElasticsearchException) ex).toXContent(builder, params);
   } else {
     builder.field("type", getExceptionName(ex));
     builder.field("reason", ex.getMessage());
     if (ex.getCause() != null) {
       builder.field("caused_by");
       builder.startObject();
       toXContent(builder, params, ex.getCause());
       builder.endObject();
     }
     if (params.paramAsBoolean(
             REST_EXCEPTION_SKIP_STACK_TRACE, REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT)
         == false) {
       builder.field("stack_trace", ExceptionsHelper.stackTrace(ex));
     }
   }
 }
コード例 #2
0
 @Override
 public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
   Throwable ex = ExceptionsHelper.unwrapCause(this);
   if (ex != this) {
     toXContent(builder, params, this);
   } else {
     builder.field("type", getExceptionName());
     builder.field("reason", getMessage());
     for (String key : headers.keySet()) {
       if (key.startsWith("es.")) {
         List<String> values = headers.get(key);
         xContentHeader(builder, key.substring("es.".length()), values);
       }
     }
     innerToXContent(builder, params);
     renderHeader(builder, params);
     if (params.paramAsBoolean(
             REST_EXCEPTION_SKIP_STACK_TRACE, REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT)
         == false) {
       builder.field("stack_trace", ExceptionsHelper.stackTrace(this));
     }
   }
   return builder;
 }