Open Closed

Validation or Business exception message property not working. Angular UI model title is default all the time #5264


User avatar
0
ndeol created
  • ABP Framework version: 7.1
  • UI type: Angular
  • DB provider: MongoDB
  • Tiered (MVC) or Identity Server Separated (Angular): yes Microservice Solution
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

I have seen in validation exception and Business exception as well . I am unable to change message property of object returned from api.

{
    "error": {
        "code": null,
        "message": "Your request is not valid!",
        "details": "The following errors were detected during validation.\r\n - File Size cannot be bigger than 5mb\r\n",
        "data": {},
        "validationErrors": [
            {
                "message": "File Size cannot be bigger than 5mb",
                "members": null
            }
        ]
    }
}

Even though I add custom message property like below its discarded and overwritten

var validations = new List<ValidationResult>() { new ValidationResult("File Size cannot be bigger than 5mb") };
throw new AbpValidationException(message: "teesting", validations);

I also tried to use business exception but same issue. Even you pass custom message which shows up on Angular UI model as title, Default error logic overwrites it. Can you please point to me to right direction how to achieve custom Angular Ui model title for each error.


5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can check this: https://docs.abp.io/en/abp/latest/UI/Angular/HTTP-Requests#http-error-handling

  • User Avatar
    0
    ndeol created

    from Angular source code it seems there are default titles for each type of error and there is no way to make is different for each error.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    you need to custom the error handle. https://docs.abp.io/en/abp/latest/UI/Angular/HTTP-Requests#custom-http-error-handler

  • User Avatar
    0
    ndeol created

    Angular code is not the problem I guess . When I pass custom message property from server side like this

    var validations = new List() { new ValidationResult("File Size cannot be bigger than 5mb") };
    throw new AbpValidationException(message: "testing 1 2 3", validations);
    

    API still returns message to default message for validations. Is there any way to override tis message.

    {
        "error": {
            "code": null,
        **    "message": "Your request is not valid!",**
            "details": "The following errors were detected during validation.\r\n - File Size cannot be bigger than 5mb\r\n",
            "data": {},
            "validationErrors": [
                {
                    "message": "File Size cannot be bigger than 5mb",
                    "members": null
                }
            ]
        }
    }
    
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This is by design. you can try add your own exception.

    For example:

    public class MyValidationException : AbpValidationException, IUserFriendlyException
    {
        public MyValidationException(string message, List<ValidationResult> validationResults) : base(message: message,
            validationResults)
        {
        }
    }
    
    var validations = new List() { new ValidationResult("File Size cannot be bigger than 5mb") };
    throw new MyValidationException(message: "testing 1 2 3", validations);
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19