Open Closed

UserFriendlyException message not shown on client side #9820


User avatar
0
DominaTang created

ABP 8 MicroService architect, when backend throw an UserFriendlyException, the message not showing in Angular client, instead an Internal error message is shown


5 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • In ABP, when you throw a UserFriendlyException on the backend, the message should be sent to the client as-is. If your Angular client is showing a generic "Internal error" message instead, this usually means the exception is not being recognized as a user-friendly error, or the error handling pipeline is not configured correctly.

    To ensure UserFriendlyException messages are shown on the Angular client:

    1. Throw UserFriendlyException in the backend:
    throw new UserFriendlyException("Your custom message here");
    

    Or, for localization:

    throw new UserFriendlyException(L["YourLocalizedKey"]);
    
    1. Check Exception Localization Configuration: Make sure you have configured AbpExceptionLocalizationOptions if you are using localization for exception messages.
    Configure<AbpExceptionLocalizationOptions>(options =>
       {
           options.MapCodeNamespace("YourProjectNamespace", typeof(YourResource));
       });
    
    1. Angular Error Handling: ABP Angular UI uses a global HTTP interceptor and error handler to display user-friendly messages. If you have customized or replaced the default error handling, ensure you are not swallowing or replacing the error message.

      • The error message from UserFriendlyException should be available in the HTTP error response as error.error.message.
      • The ABP Angular template uses a toast or snackbar to show this message.
    2. Check for Microservice Gateway Issues: If you are using a gateway (like Ocelot or YARP), ensure it is not modifying or hiding the error response from the backend.

    3. Sample: Backend:

    throw new UserFriendlyException("This is a user-friendly error!");
    

    Angular (in your service or component):

    this.yourService.callApi().subscribe({
         next: () => { /* success */ },
         error: (err) => {
           // err.error.message should contain your UserFriendlyException message
           this.toastService.showError(err.error.message);
         }
       });
    
    1. If you are using the default ABP Angular error handling, and still see "Internal error", check if:
      • The backend is returning a proper ABP error response (with error.message).
      • The Angular app is not running in production mode with error suppression.
      • There is no proxy/gateway stripping the error details.

    If you follow these steps and the problem persists, verify that your backend and frontend are both using compatible ABP versions and that no custom middleware or error handler is interfering with the error response.

    Sources:


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    DominaTang created

    If the API call handle the error message, the Angular UI does catch the UserFriendlyException message, say the angular show the message in a toaster or display direct on a UI element. However, at the same time, the Generic Internal Error exception window also shows up. I don't want the second one, or the second one should be message in UserFriendlyException

    Actually I tried UserFriendlyException, BusinessException, Exception, from backend Swagger, the error code is 400, the response content is plain text error message, instead of JSON format. I have this code below in HttpApi.Host module file:

    if (env.IsDevelopment())
    		{
    			//app.UseDeveloperExceptionPage();
    		}
    
    		app.UseCorrelationId();
    		app.UseAbpRequestLocalization();
    		app.UseStaticFiles();
            app.UseAbpExceptionHandling();
    
            app.UseRouting();
    

    Another interesting thing is, I use this code below in a controller method:

    return StatusCode(400, new { error = new { message = "Your user-friendly message in json", details = (string?)null, code = (string?)null } });

    The angular side doesn't display the message neither

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    when backend throw an UserFriendlyException,

    Can you share your backend code?

    Can you check your HTTP call response in Chrome Network Panel? What are response headers and body?

    Thanks.

  • User Avatar
    0
    DominaTang created

    The backend is as above in Api project. The client angular network tab, response is plain error message.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Can you share the screenshots of the response headers and body?

    eg:

    Thanks.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 01, 2025, 08:37