背景介绍:基于netcore2.2开发api接口程序,自定义了一个异常捕获中间件,用于捕获未经处理的异常以及状态码404、500等访问(设计的出发点就是,出现了非200的响应,我这边全部会进行处理成200,并返回固定格式的JSON格式数据),并进行统一的信息返回。
返回的JSON实体定义如下:
中间件部分代码如下所示:
异常截图如下:
文字信息:fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLVT9ADLSD7M", Request id "0HLVT9ADLSD7M:00000001": An unhandled exception was thrown by the application.
System.ObjectDisposedException: Cannot access a closed Stream.
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.MemoryStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at CommonPlatform.Core.Middlewares.ApiGlobalExceptionMiddleware.Invoke(HttpContext context) in E:\work\project\MWCS\01.code\CommonPlatform\CommonPlatform.Core\Middlewares\ApiGlobalExceptionMiddleware.cs:line 96
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
以上就是本人遇到的问题,目前还未找到解决方案,故发此博文寻求众开发大佬的帮助,先提前感谢!欢迎大家留言支招!
来源:oschina
链接:https://my.oschina.net/u/4267090/blog/4287350