servicestack - 即使禁用了 DebugMode 和 WriteErrorsToResponse,响应也包括堆栈跟踪
问题描述
我在最新版本的 ServiceStack (5.6.0) 上运行自托管 API。
我正在努力在请求处理管道的早期处理异常。更具体地说,当请求包含|
字符时。API 将始终使用 stackTrace 返回完整的错误响应。即使在带有DebugMode
和WriteErrorsToResponse
禁用的发布版本中。
通常我没有问题,因为大多数问题都是在带有自定义错误响应 DTO 的自定义 ServiceRunner 中处理的。但是这个错误发生在调用 ServiceRunner 之前。
如何禁用 stackTrace?是否可以用自定义响应替换错误响应?
这是我在点击时会收到的响应对象,例如http://localhost:80/*|?
{
"responseStatus": {
"errorCode": "ArgumentException",
"message": "Illegal characters in path.",
"stackTrace": " at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)\r\n at System.IO.Path.InternalCombine(String path1, String path2)\r\n at System.IO.FileSystemEnumerableIterator`1.GetFullSearchString(String fullPath, String searchPattern)\r\n at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)\r\n at System.IO.DirectoryInfo.InternalGetFiles(String searchPattern, SearchOption searchOption)\r\n at ServiceStack.VirtualPath.FileSystemVirtualDirectory.GetFileFromBackingDirectoryOrDefault(String fName)\r\n at ServiceStack.VirtualPath.AbstractVirtualPathProviderBase.GetFile(String virtualPath)\r\n at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()\r\n at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)\r\n at ServiceStack.Host.HttpListener.ListenerRequest.GetFile()\r\n at ServiceStack.Host.HttpListener.ListenerRequest.get_IsFile()\r\n at ServiceStack.HttpHandlerFactory.GetHandlerForPathInfo(IHttpRequest httpReq, String filePath)\r\n at ServiceStack.HttpHandlerFactory.GetHandler(IHttpRequest httpReq)\r\n at ServiceStack.AppHostHttpListenerBase.<ProcessRequestAsync>d__8.MoveNext()",
"errors": null,
"meta": null
}
}
解决方案
现在应该从这个提交中解决这个问题,它不再显示 StackTraces of HTTP Listener Exceptions when Config.DebugMode = false
.
此更改从 v5.6.1+ 开始可用,现在可在 MyGet 上使用。
推荐阅读
- machine-learning - 为什么 PyTorch DQN 教程中的 CNN 卷积输出大小使用“kernel_size -1”计算?
- java - 将文件路径从文件树传输到另一个类
- python - python中的可变和不可变对象
- email - 交易失败。服务器响应为:5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
- c# - 如何检查和验证令牌的标头?
- python - VTK:关于坐标转换的问题:显示与世界
- docker - 自动编辑 dockerized 容器中的文件
- html - 带有倾斜标签的 CSS 复选框
- android - Chrome 的顶部栏出现在已安装的独立 PWA 中
- c# - 接口 - 方法返回实现它的具体类的类型的对象