Browse Source

Include error code in multi-tenancy middleware AJAX error response

pull/26223/head
maliming 2 months ago
parent
commit
1300a929e4
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 6
      framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs
  2. 1
      framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_MultiTenancyMiddlewareErrorPageBuilder_Tests.cs

6
framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyOptions.cs

@ -18,6 +18,7 @@ using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Volo.Abp.AspNetCore.MultiTenancy.Views;
using Volo.Abp.AspNetCore.RazorViews;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Http;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Threading;
@ -76,7 +77,10 @@ public class AbpAspNetCoreMultiTenancyOptions
}
else if (context.Request.IsAjax())
{
var error = new RemoteServiceErrorResponse(new RemoteServiceErrorInfo(exception.Message, exception is BusinessException businessException ? businessException.Details : string.Empty));
var error = new RemoteServiceErrorResponse(new RemoteServiceErrorInfo(
exception.Message,
exception is BusinessException businessException ? businessException.Details : string.Empty,
(exception as IHasErrorCode)?.Code));
var jsonSerializerOptions = context.RequestServices.GetRequiredService<IOptions<JsonOptions>>().Value.SerializerOptions;

1
framework/test/Volo.Abp.AspNetCore.MultiTenancy.Tests/Volo/Abp/AspNetCore/MultiTenancy/AspNetCoreMultiTenancy_MultiTenancyMiddlewareErrorPageBuilder_Tests.cs

@ -33,6 +33,7 @@ public class AspNetCoreMultiTenancy_MultiTenancyMiddlewareErrorPageBuilder_Tests
var result = await response.Content.ReadAsStringAsync();
var error = JsonSerializer.Deserialize<RemoteServiceErrorResponse>(result, new JsonSerializerOptions {PropertyNamingPolicy = JsonNamingPolicy.CamelCase});
error.Error.ShouldNotBeNull();
error.Error.Code.ShouldBe("Volo.AbpIo.MultiTenancy:010001");
error.Error.Message.ShouldBe("Tenant not found!");
error.Error.Details.ShouldBe("There is no tenant with the tenant id or name: abpio");
}

Loading…
Cancel
Save