Skip to content

Instantly share code, notes, and snippets.

@antonydenyer
Created September 20, 2012 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonydenyer/3755906 to your computer and use it in GitHub Desktop.
Save antonydenyer/3755906 to your computer and use it in GitHub Desktop.
RestServiceBase override
public abstract class RestServiceBase<TRequest> : global::ServiceStack.ServiceInterface.RestServiceBase<TRequest>
{
private IErrorResponseFactory _errorResponseFactory;
private IErrorResponseFactory ErrorResponseFactory
{
get { return _errorResponseFactory ?? (_errorResponseFactory = new ErrorResponseFactory()); }
set { _errorResponseFactory = value; }
}
private static readonly ILog Log = LogManager.GetLogger(typeof(ServiceBase<>));
protected override object HandleException(TRequest request, Exception ex)
{
if (ex.InnerException != null && !(ex is IHttpError))
ex = ex.InnerException;
var responseStatus = ResponseStatusTranslator.Instance.Parse(ex);
if (EndpointHost.UserConfig.DebugMode)
{
responseStatus.StackTrace = GetRequestErrorBody() + ex;
}
Log.Error("ServiceBase<TRequest>::Service Exception", ex);
var errorResponse = ErrorResponseFactory.CreateErrorResponse(request, ex, responseStatus);
AfterEachRequest(request, errorResponse ?? ex);
return errorResponse;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment