Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Not sure the bext approach to display exceptions like db exceptions to the client (ajax calls)? Should I place a try/catch in the controller bellow? Currently, I get a generic exception to my ajax call?

Controller:

// GET: Agency Grants 
    public JsonResult GetAgencyGrants(int agencyID)
    {
        AuditDAL ad = new AuditDAL();
        var grants = ad.GetAgencyGrants(agencyID); //exception here
        return this.Json(grants.ToList());
    } 

Ajax call:

function GetAuditTypes(container) {
    $.ajax({
        url: '/AMS/Audit/GetAuditTypes',
        type: 'post',
        success: function (result) {
            $.each(result, function (i, item) {
                container.append($('<option/>').text(result[i].Audit_Type_Desc).attr('value', result[i].Audit_Type_ID));
            });
        },
        error: function (xhr, err) {
            alert("GetAuditTypes not returned: " + formatErrorMessage(xhr, err)); 
        }
    });
}

formatting function:

// formats errors returned
function formatErrorMessage(jqXHR, exception) {

    if (jqXHR.status === 0) {
        return ('Not connected.\nPlease verify your network connection.');
    } else if (jqXHR.status == 404) {
        return ('The requested page not found. [404]');
    } else if (jqXHR.status == 500) {
        return ('Internal Server Error [500].');
    } else if (exception === 'parsererror') {
        return ('Requested JSON parse failed.');
    } else if (exception === 'timeout') {
        return ('Time out error.');
    } else if (exception === 'abort') {
        return ('Ajax request aborted.');
    } else {
        return ('Uncaught Error.\n' + jqXHR.responseText);
    }
}

I keep getting Internal Server error instead of the stored proc is missing (the real exception).

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.