Ends in:
4 DAYS
14 HRS
1 MIN
47 SEC
Ends in:
4 D
14 H
1 M
47 S
Open Closed

Identity module error handling #8215


User avatar
0
BenS-FreshRF created
  • ABP Framework version: v8.3.2
  • UI Type: Blazor WASM
  • Database System: EF Core (PostgreSQL)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace: Failed to load resource: the server responded with a status of 403 ()
  • Steps to reproduce the issue: Create a new User with a username that is the same as another users Email

This error is expected and normal, its failing correctly when attempting to add a new User with some dodgy data.

However its resulting in a big 403 Unhandled Exception, with a full stack trace dumped to the console, and a big "Unhandled Exception" error message to the user for what is basically a validation error.

With the Identity Module the User form as well as the API call and all surrounding work is handled by the ABP libraries, and I can't find any documentation on how to shim in our own exception handling so that we can swallow these kinds of errors and present a nicer and more useful error message to the user.

Is there any way to provide some nicer error messages to the end user from an ABP module that is completely standalone?


6 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share some screenshots and error logs?

    Thanks.

  • User Avatar
    0
    BenS-FreshRF created

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will fix this.

    The message text should be Username xxx is already taken.

  • User Avatar
    0
    BenS-FreshRF created

    The username in this case was not already taken, but the username does equal the email address of another user so maybe the same error message applies.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    ok, I will fix this and share a temporary solution.

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We will fix this in 9.0

    https://github.com/abpframework/abp/pull/21263


    You can override the Volo.Abp.Identity:InvalidUserName text and add the patch code below to your API website.

    "Volo.Abp.Identity:InvalidUserName": "Username '{0}' is invalid, can only contain letters or digits."

    public class Program
    {
        public async static Task<int> Main(string[] args)
        {
            var identityStrings = (typeof(AbpIdentityResultExtensions)
                .GetField("IdentityStrings", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)
                ?.GetValue(null) ?? new Dictionary<string, string>()).As<Dictionary<string, string>>();
    
            if (identityStrings.ContainsKey("InvalidUserName"))
            {
                identityStrings["InvalidUserName"] = "Username '{0}' is invalid.";
            }
    
    

    https://abp.io/community/articles/how-to-override-localization-strings-of-depending-modules-ba1oy03l

Made with ❤️ on ABP v9.1.0-preview. Updated on November 28, 2024, 07:27