Base solution for your next web application
Open Closed

Throwing UserFriendlyException instead of generic Exception #1700


User avatar
0
raffee created

Hi, I have a need to display validation error details to the user (PL). We don't want to stop the automatic validation based on data-annotations, which works great, but it seems to be sending a generic exception, which is displayed on the client side as "Internal Error Happened". So I was wondering if there is a way to force the internal validation to throw a User Friendly Exception, so that we can display the detailed message to the user.

Thanks! Raffee


5 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I always suggest to make client side validate validation so invalid data never sent to the server and data annotations never throw exceptions (they are there for security, data integrity and other reasons). But.. if you want to show a different message, actually ABP sends all validation errors in the returned AJAX response (see the incoming json data in the server response). So, you may try to override default error message handler and show validation details to the user. You can override this function in your javascript code: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Web.Resources/Abp/Framework/scripts/libs/abp.jquery.js#L69">https://github.com/aspnetboilerplate/as ... ery.js#L69</a> like abp.ajax.showError = function(error) { ... }; In this method, you can check validation errors and so on...

  • User Avatar
    0
    raffee created

    Hi, Thank you for the quick reply :) We do have client side validation of course, but we also have server side validation, and we prefer to have as much detailed control as possible over what is displayed to the clients. I will try your suggestion and get back to you.

    Regards, Raffee

  • User Avatar
    0
    raffee created

    Hi again, Actually here is the JSON we are getting from the server:

    {"result":null,"targetUrl":null,"success":false,"error":{"code":0,"message":"An internal error occurred during your request!","details":null,"validationErrors":null},"unAuthorizedRequest":false,"__abp":true}

    We already disabled the automatic ABP error handling on the client, and we implemented our own, but we still don't have the details to work with. I could be wrong, but I believe we need a setting to tell the server to send us all the validation details instead of a generic "An internal error occurred during your request!" message.

    Thanks, Raffee

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It might be related to customErrors on your web.config. Can you change it's value to "On" and then try again ?

  • User Avatar
    0
    raffee created

    Hi, Thank you for your reply. I tried your suggestion but I keep getting the exact same error.

    Raffee