I'm calling a Razor Pages handler from AJAX like this:
$.ajax({
    url: '?handler=Delete',
    data: {
        id: $(this).data('id')
    }
})
.fail(function (e) {
    alert(e.responseText);
});
And here's my handler that tests what happens if an exception occurs:
public async System.Threading.Tasks.Task OnGetDelete(int id)
{
    throw new Exception("This is an exception.");
}
If an exception is thrown in my handler, then I want to display a description of the error. The problem is that e.responseText contains way more information than I want to display to the user. It includes a description of the exception, along with the stack trace, headers and a lot of other stuff.
In the example above, I'd want to only display "This is an exception.". Is my only solution to try and parse the message from e.responseText? Is this what other people are doing?
 
    

