Skip to content

Instantly share code, notes, and snippets.

@mmcgahan
Created August 18, 2015 19:21
Show Gist options
  • Save mmcgahan/5d84b0b841a7796bc46d to your computer and use it in GitHub Desktop.
Save mmcgahan/5d84b0b841a7796bc46d to your computer and use it in GitHub Desktop.
diff --git a/modules/chapstick/src/main/java/com/meetup/business/MeetstacheBusiness.java b/modules/chapstick/src/main/java/com/meetup/business/MeetstacheBusiness.java
index 58fb1ae..a233b91 100644
--- a/modules/chapstick/src/main/java/com/meetup/business/MeetstacheBusiness.java
+++ b/modules/chapstick/src/main/java/com/meetup/business/MeetstacheBusiness.java
@@ -18,6 +18,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Maps;
+import com.google.common.collect.ImmutableMap;
import org.json.JSONObject;
@@ -59,6 +60,7 @@ public class MeetstacheBusiness {
public static final String API_RESULT = "api_result";
public static final String REQUEST_PARAMS = "request_params";
+ public static final String STACKTRACE_TEMPLATE_KEY = "stackTrace";
/** represents the type of template to render. may be one of mustache of handlebars
* ( default is mustache for now )
@@ -393,10 +395,20 @@ public class MeetstacheBusiness {
@Override public String getResponseString() {
if ( C.ONLY_ON_DEV ) {
for ( Throwable e : this.getContent().asSet() ) {
+ String renderedStackTrace;
StringWriter stringWriter = new StringWriter();
e.printStackTrace( new PrintWriter( stringWriter ) );
- String stackTrace = "<pre style='font-size:0.7em;color:red;background-color:#fffefe'>" + stringWriter.toString() + "</pre>";
- return stackTrace;
+ String stackTrace = stringWriter.toString();
+ Map<String, Object> stackTraceMap = ImmutableMap.of("stackTrace", (Object) stackTrace);
+ try {
+ renderedStackTrace = Renderer.HANDLEBARS.renderPackaged(STACKTRACE_TEMPLATE_KEY, stackTraceMap);
+ }
+ catch ( Exception err ) {
+ log.errorf(err, "Something went wrong rendering handlebars for stackTraceMap %s", stackTraceMap);
+ renderedStackTrace = "Error printing stack trace, see logs for details";
+ }
+
+ return renderedStackTrace;
}
}
return "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment