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 December 13, 2024, 06:09