With ServiceStack, it's important to implement exception handling/logging in two places:
Inside of each ServiceRunner<T>
.
public class MyServiceRunner<T> : ServiceRunner<T>
{
public override object HandleException(IRequestContext requestContext, T request, Exception ex)
{
// Implement your exception handling/logging here.
// T request is your request DTO.
}
}
Inside of AppHost, so that you can handle unhandled exceptions occuring outside of services.
public override void Configure(Container container)
{
ExceptionHandler = (req, res, operationName, ex) =>
{
//Handle Unhandled Exceptions occurring outside of Services
//E.g. Exceptions during Request binding or in filters:
}
}
My Question:
In ServiceStack v4 the Request DTO is available from IRequest.Dto
, but you would instead register your Service and Unknown Exception handlers with IAppHost.ServiceExceptionHandlers
and IAppHost.UncaughtExceptionHandlers
In ServiceStack V3, you could register a GlobalRequestFilter that stores the Request DTO in IRequestContext.Items
dictionary which you can get later from the Request Context.