Created
September 20, 2012 13:28
-
-
Save antonydenyer/3755906 to your computer and use it in GitHub Desktop.
RestServiceBase override
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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