我的情况是这样的:在OpenRasta中,您应该如何处理编解码器错误或异常?
- 客户端应用程序执行对抗OpenRasta暴露端点的HTTP POST。
- 请求的主体包含导致编解码器出现问题的错误 - 这是
OpenRasta.Codecs.IMediaTypeReader
的自定义实现。这将JSON负载转换为处理程序期望的POCO。 - 编解码器会以有用的方式抛出一个描述错误的异常。例如:
Newtonsoft.Json.JsonReaderException: After parsing a value an unexpected character was encountered: ". Line 4, position 5.
- 客户端应用程序收到HTTP 405 - MethodNotAllowed。客户端没有看到任何异常细节。
如果编解码器被修改搭上JsonReaderException
并返回Missing.Value
,类似于Implementing a codec维基,然后客户端会收到一个HTTP 500 - 内部服务器错误。响应的身体还介绍了以下异常:
System.InvalidOperationException: The operation is not ready for invocation.
at OpenRasta.OperationModel.MethodBased.MethodBasedOperation.Invoke()
at OpenRasta.OperationModel.Interceptors.OperationWithInterceptors.<Invoke>b__0()
at OpenRasta.OperationModel.Interceptors.OperationWithInterceptors.Invoke()
at OpenRasta.OperationModel.OperationExecutor.Execute(IEnumerable`1 operations)
at OpenRasta.Pipeline.Contributors.OperationInvokerContributor.ExecuteOperations(ICommunicationContext context)
at OpenRasta.Pipeline.PipelineRunner.ExecuteContributor(ICommunicationContext context, ContributorCall call)
我应该如何修改我的应用程序,以便:
- 客户端收到一个HTTP 400错误的请求。
- 客户端收到一个字符串,其中包含解码器中遇到的异常的详细信息。
在Google Groups上找到这条相关线索:http://groups.google.com/group/openrasta/browse_thread/thread/5deb77ebdc78d79f – Iain 2012-03-29 15:15:16