diff --git a/apps/vue/src/utils/http/axios/checkStatus.ts b/apps/vue/src/utils/http/axios/checkStatus.ts index 142a47c14..d656ea9e3 100644 --- a/apps/vue/src/utils/http/axios/checkStatus.ts +++ b/apps/vue/src/utils/http/axios/checkStatus.ts @@ -83,7 +83,7 @@ export function checkStatus( export function checkResponse(response: any): string | undefined { // 会话超时 - if (response.status === 401) { + if (response?.status === 401) { const userStore = useUserStoreWithOut(); userStore.setToken(undefined); userStore.setSessionTimeout(true); @@ -97,11 +97,11 @@ export function checkResponse(response: any): string | undefined { return undefined; } - if (response.data.Enterprises) { + if (response?.data.Enterprises) { return response.data.Enterprises; } - let errorJson = response.data.error; + let errorJson = response?.data.error; // abp框架抛出异常信息 if (response.headers['_abperrorformat'] === 'true') { @@ -124,18 +124,18 @@ export function checkResponse(response: any): string | undefined { } // oauth错误信息 - if (response.data.error_description) { + if (response?.data.error_description) { error(response.data.error_description); return response.data; } // 其他错误 - if (response.data.error.details) { + if (response?.data.error.details) { error(response.data.error.details); return response.data.error.details; } - if (response.data.error.message) { + if (response?.data.error.message) { error(response.data.error.message); return response.data.error.message; } diff --git a/aspnet-core/framework/common/LINGYUN.Abp.AspNetCore.Wrapper/LINGYUN/Abp/AspNetCore/Wrapper/DefaultHttpResponseWrapper.cs b/aspnet-core/framework/common/LINGYUN.Abp.AspNetCore.Wrapper/LINGYUN/Abp/AspNetCore/Wrapper/DefaultHttpResponseWrapper.cs index fb5c8e48e..c0cd1d93e 100644 --- a/aspnet-core/framework/common/LINGYUN.Abp.AspNetCore.Wrapper/LINGYUN/Abp/AspNetCore/Wrapper/DefaultHttpResponseWrapper.cs +++ b/aspnet-core/framework/common/LINGYUN.Abp.AspNetCore.Wrapper/LINGYUN/Abp/AspNetCore/Wrapper/DefaultHttpResponseWrapper.cs @@ -1,5 +1,7 @@ using LINGYUN.Abp.Wrapper; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -7,29 +9,40 @@ namespace LINGYUN.Abp.AspNetCore.Wrapper; public class DefaultHttpResponseWrapper : IHttpResponseWrapper, ITransientDependency { + public ILogger Logger { protected get; set; } + protected AbpWrapperOptions Options { get; } public DefaultHttpResponseWrapper(IOptions options) { Options = options.Value; + + Logger = NullLogger.Instance; } public virtual void Wrap(HttpResponseWrapperContext context) { - context.HttpContext.Response.StatusCode = context.HttpStatusCode; - if (context.HttpHeaders != null) + if (!context.HttpContext.Response.HasStarted) { - foreach (var header in context.HttpHeaders) + context.HttpContext.Response.StatusCode = context.HttpStatusCode; + if (context.HttpHeaders != null) { - if (!context.HttpContext.Response.Headers.ContainsKey(header.Key)) + foreach (var header in context.HttpHeaders) { - context.HttpContext.Response.Headers.Append(header.Key, header.Value); + if (!context.HttpContext.Response.Headers.ContainsKey(header.Key)) + { + context.HttpContext.Response.Headers.Append(header.Key, header.Value); + } } } + if (!context.HttpContext.Response.Headers.ContainsKey(AbpHttpWrapConsts.AbpWrapResult)) + { + context.HttpContext.Response.Headers.Append(AbpHttpWrapConsts.AbpWrapResult, "true"); + } } - if (!context.HttpContext.Response.Headers.ContainsKey(AbpHttpWrapConsts.AbpWrapResult)) + else { - context.HttpContext.Response.Headers.Append(AbpHttpWrapConsts.AbpWrapResult, "true"); + Logger.LogWarning("HTTP response has already started, cannot set headers and status code!"); } } } diff --git a/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs b/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs index 00c89938b..b23e2323a 100644 --- a/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs +++ b/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs @@ -90,10 +90,6 @@ await context.HttpContext.RequestServices.GetRequiredService() { @@ -106,8 +102,10 @@ await context.HttpContext.RequestServices.GetRequiredService() { @@ -87,6 +83,11 @@ await context.HttpContext.RequestServices.GetRequiredService