Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Would you please help me with the below issue?

We are returning the exception throw JSON object in the JQUERY call?

Below is how we are retuning the exception in the controller.

C#
protected JsonResult ThrowJSONError(Exception e)
{
    return Json(new { Message = e.Message }, JsonRequestBehavior.AllowGet);
}



below is how we capturing the exception:

var getSubDecisions = function(p) {
$.blockUI();
var url = window.location.pathname + "/ABC/XYZ";
url = url.replace('//', '/');
$.ajax({
url: url,
data: {
decisionId: $(p).val()
},
type: "POST",
datatype: "json",
complete: function () {
$.unblockUI();
},
success: function (result) {

},
error: function (xhr, status, error) {
handleServerException(xhr);
}
});
};

lets assume that there is an exception in the above AJAX. then it would go the error: (block) , and then

C#
// Genernal Purpose function to handle/display exceptions
var handleServerException = function (xhr) {
    var errors = [];
    //var errorMessage = $.parseJSON(xhr.responseText);
    errors.push(xhr.responseText);
    showErrors(errors, "DecisionForm");
};

// Show validation errors in overlay
var showErrors = function (errors, formName) {
    // Clear errors from Validation Summary control
    clearValidationSummaryForm(formName);



    var currentForm = $('form[name="' + formName + '"]');

    // Add error messages to the list
    $.each(errors, function (index, value) {
        //message parsing
        var errorMessage = value;
        currentForm.find('div[data-valmsg-summary] ul').append('<li>' + errorMessage + '</li>');
    });

    // Change the css style from non-error to error state
    currentForm.find('div[data-valmsg-summary]')
        .removeClass('validation-summary-valid')
        .addClass('validation-summary-errors');

    // Show the div overlay that is used to display the errors
    currentForm.find('div.validationSummary').show();
};



As you can see above, when there is an exception in the AJAX call , it would go the Error black , from there it would to go handleServerException function and from there it would go to showErrors()... in the show errors function we are just trying to push the message to the UI... it works fine for the page validation erros but when it is an AJAX error.. it is throwing the bad request error instead of the exception we passed... but it works fine when we test through visual studio and it also works fine if we test application on the deployed server but.. outside the server it is throwing (pushing) bad request instead of the exception we are suppose to see..

Please let me know if you have any question about the issue.

Thanks for your help in advance.
Posted
Comments
ZurdoDev 5-Dec-14 11:54am    
Sounds like your url may actually be the problem if it works from the server but not outside.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900