Ends in:
7 DAYS
15 HRS
36 MIN
50 SEC
Ends in:
7 D
15 H
36 M
50 S
Open Closed

How to throw BusinessException with message without error code? #4176


User avatar
0
nhontran created

Hi, I want to throw BusinessException with custom message without passing the error code or using error code does not exist in en.json:

// no error code
throw new BusinessException(null, "custom error message", null);

// error code does not exist
throw new BusinessException("NoErrorCode", "custom error message", null);

But received the output as below:

// no error code
{
  "error": {
    "code": null,
    "message": "An internal error occurred during your request!",
    "details": null,
    "data": {},
    "validationErrors": null
  }
}

// error code does not exist
{
  "error": {
    "code": "NoErrorCode",
    "message": "An internal error occurred during your request!",
    "details": null,
    "data": {},
    "validationErrors": null
  }
}

Any idea?


3 Answer(s)
  • User Avatar
    0
    nhontran created

    Hi, anyone can help us on this query?

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, you can use throw UserFriendlyException for this purpose.

    See the documentation for more info.

  • User Avatar
    0
    nhontran created

    Hi @EngicanV, thanks for the reply.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06