-
ABP Framework version: V4.2.2
-
UI type: MVC
-
DB provider: EF Core
-
Tiered (MVC) or Identity Server Separated (Angular): no
-
Exception message and stack trace:
-
Steps to reproduce the issue:
I have the following code in my OnPost
of a page where i am throwing a new UserFriendlyException
public virtual async Task OnPostAsync()
{
var tenant = await TenantRepository.FindByNameAsync(Tenant.Name);
if (tenant != null)
{
throw new UserFriendlyException(message: "Tenant Name already exists please choose another");
}
However the page go to a 403 Forbidden page and not shows a popup dialog, can you let me know what I am doing wrong
8 Answer(s)
-
0
-
0
no a dialogbox which shows like the one that often says "internal error occured"
like above but with mu custom messgae of tenant not found
-
0
Hi @learnabp, I can't see UserFriendlyException but I'll suggest something below. If you already construct your exception same, please share your exception class too.
Make sure your exception is a DomainException and it has an error code and your localization json files have a resource with that error code as key.
You can examine 'AuthorAlreadyExistsException' in this sample
-
0
what do you mean by DomainException .... do i have to throw the BusinessException in Domain Project
-
0
what do you mean by DomainException .... do i have to throw the BusinessException in Domain Project
i am throwing the exception in my OnPost when i submit the form on a page to check if tenant exists
if (tenant != null) { throw new UserFriendlyException(message: "Tenant Name already exists please choose another"); }
-
0
If exception is inherited from Business exception and it has errorcode, exception detail text will be displayed from resources, exception message won't be displayed in UI automatically. You have to add a resource for errorcode of your exception
-
0
@learnabp
let me introduce for your situation:-
As a best-practice, BusinessException should be thrown from Domain layer. So You have to create your Exception in your Domain layer:
public class UserFriendlyException : BusinessException { public UserFriendlyException(SerializationInfo serializationInfo, StreamingContext context) : base(serializationInfo, context) { } public UserFriendlyException(string tenantName) { // As an example, place your awesome unique code here Code = "Acme.BookStore:0001"; WithData(nameof(TenantName), tenantName); } public string TenantName { get; set; } }
-
You can throw like that:
if (tenant != null) { throw new UserFriendlyException(Tenant.Name); }
-
You can localize what user sees in your localization files:
en.json{ "culture": "en", "texts": { "Acme.BookStore:0001": "Tenant Name {TenantName} already exists please choose another", //... } }
You can display different messages for each language with that.
If you create a Business Exception like that, you won't see "internal error occured".
Let me know if that helps or not. @learnabp
-
-
0
This question has been automatically marked as stale because it has not had recent activity.