1

I have a controller, which return some object and in bad cases it should transmit error messages to error part in ajax. The responseText is not accept cause tomcat returns to me a whole page with tags and full stack trace, but I need just couple of words to show this message to user.

    @RequestMapping(value = {"/charts"}, method = RequestMethod.POST)
    @ResponseBody
    public Chart handleSelectionFiled(@RequestBody Chart chart) {

        try{
            chart.doSmth();
        } catch (Exception e) {
            //some code to transmit exception message - this is my question    
        }
        return chart;
     }

ajax function

$.ajax({
        contentType: 'application/json',
        mimeType: 'application/json',
        type: frm.attr('method'),
        url: frm.attr('action'),
        dataType: 'json',
        data: data["chosenFile"],
        success: function (response) {
            turnOffPreLoader($("#defects_info"),response);
            $('#selectionForm').submit();

        },
        error: function (jqXHR, textStatus, errorThrown) {
            $("#result").text(errorThrown);
            turnOffPreLoader($("#defects_info"),"default:50");
        }
    });
shibli049
  • 528
  • 12
  • 31
jenius
  • 257
  • 1
  • 4
  • 17

0 Answers0