Permalink
Browse files

Added `IHttpRequest Request` and IHttpResponse Response` convenience …

…properties in ServiceBase (just calls RequestContext.Get<T>()).

Don't send StackTraces for unhandled exceptions when DebugMode is not enabled
  • Loading branch information...
1 parent 9238613 commit 1e0bb3fadb4dc2874f4ff49e6831778847912a10 @mythz mythz committed Jul 31, 2012
@@ -68,6 +68,16 @@ public IAppHost GetAppHost()
public IRequestContext RequestContext { get; set; }
+ public IHttpRequest Request
+ {
+ get { return RequestContext.Get<IHttpRequest>(); }
+ }
+
+ public IHttpResponse Response
+ {
+ get { return RequestContext.Get<IHttpResponse>(); }
+ }
+
public ISessionFactory SessionFactory { get; set; }
public IRequestLogger RequestLogger { get; set; }
@@ -321,7 +321,7 @@ private static void WriteXmlErrorToResponse(this IHttpResponse response, string
sb.AppendLine("<ResponseStatus>");
sb.AppendFormat("<ErrorCode>{0}</ErrorCode>\n", ex.GetType().Name.EncodeXml());
sb.AppendFormat("<Message>{0}</Message>\n", ex.Message.EncodeXml());
- sb.AppendFormat("<StackTrace>{0}</StackTrace>\n", ex.StackTrace.EncodeXml());
+ if (EndpointHost.Config.DebugMode) sb.AppendFormat("<StackTrace>{0}</StackTrace>\n", ex.StackTrace.EncodeXml());
sb.AppendLine("</ResponseStatus>");
sb.AppendFormat("</{0}Response>", operationName);
@@ -335,7 +335,7 @@ private static void WriteJsonErrorToResponse(this IHttpResponse response, string
sb.AppendLine("\"ResponseStatus\":{");
sb.AppendFormat(" \"ErrorCode\":{0},\n", ex.GetType().Name.EncodeJson());
sb.AppendFormat(" \"Message\":{0},\n", ex.Message.EncodeJson());
- sb.AppendFormat(" \"StackTrace\":{0}\n", ex.StackTrace.EncodeJson());
+ if (EndpointHost.Config.DebugMode) sb.AppendFormat(" \"StackTrace\":{0}\n", ex.StackTrace.EncodeJson());
sb.AppendLine("}");
sb.AppendLine("}");
@@ -349,7 +349,7 @@ private static void WriteJsvErrorToResponse(this IHttpResponse response, string
sb.Append("ResponseStatus:{");
sb.AppendFormat("ErrorCode:{0},", ex.GetType().Name.EncodeJsv());
sb.AppendFormat("Message:{0},", ex.Message.EncodeJsv());
- sb.AppendFormat("StackTrace:{0}", ex.StackTrace.EncodeJsv());
+ if (EndpointHost.Config.DebugMode) sb.AppendFormat("StackTrace:{0}", ex.StackTrace.EncodeJsv());
sb.Append("}");
sb.Append("}");

0 comments on commit 1e0bb3f

Please sign in to comment.