当我处理服务外发生的异常时,我是否有权访问请求 dto?
Do I have access to the request dto when I'm handling exceptions occuring outside of services?
对于 ServiceStack,在两个地方实现异常 handling/logging 很重要:
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,以便您可以处理在服务之外发生的未处理异常。
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:
}
}
我的问题:
- 在 #1 中,您可以轻松访问请求 DTO(即用于记录目的)。
- 当我处理发生在服务之外的异常时,我是否有权访问请求 DTO(或等效的请求负载)?
在 ServiceStack v4 中,请求 DTO 可从 IRequest.Dto
获得,但您可以使用 IAppHost.ServiceExceptionHandlers
和 IAppHost.UncaughtExceptionHandlers
注册您的服务和未知异常处理程序
在 ServiceStack V3 中,您可以注册一个 GlobalRequestFilter,它将请求 DTO 存储在 IRequestContext.Items
字典中,稍后您可以从请求上下文中获取该字典。
对于 ServiceStack,在两个地方实现异常 handling/logging 很重要:
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,以便您可以处理在服务之外发生的未处理异常。
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: } }
我的问题:
- 在 #1 中,您可以轻松访问请求 DTO(即用于记录目的)。
- 当我处理发生在服务之外的异常时,我是否有权访问请求 DTO(或等效的请求负载)?
在 ServiceStack v4 中,请求 DTO 可从 IRequest.Dto
获得,但您可以使用 IAppHost.ServiceExceptionHandlers
和 IAppHost.UncaughtExceptionHandlers
在 ServiceStack V3 中,您可以注册一个 GlobalRequestFilter,它将请求 DTO 存储在 IRequestContext.Items
字典中,稍后您可以从请求上下文中获取该字典。