Custom http error response in JSON

Server side (PHP):

    protected function json_response($code=200, $message='', $data=null){
        http_response_code($code);
        //Output;
        header('Cache-Control: no-cache, must-revalidate');
        header('Content-type: application/json;charset=utf-8');

        $out = array(
            'code' => $code, 
            'message' => $message, 
            'data' => $data
        );
        echo json_encode($out);
        exit();
    }

Client (with datatable):

    function init_dt(){
        datatable = $t.DataTable({
            "searching": true,
            "info": true,
            "lengthChange": true,
            "paging": true,
            'serverSide': true, 
            'processing': true, 
            "ajax": {
                'url': base_url + 'admin_ajax/products/all',
                'data': function(d){
                    var $c = $('.option_panel');
                    d.store_id = $('#store').val();
                    d.campaign_id = $('#campaign').val();
                    d.cat_id = $('#cat').val();
                }, 
                error: function (xhr, error, thrown) {
                    //error( xhr, error, thrown );
                    console.log(xhr);
                    console.log(error);
                    console.log(thrown);
                    var response = xhr.responseJSON;
                    var msg = response.message;
                    alert(msg);
                }
            },
            "order": [[ 1, "desc" ], [ 0, "asc" ]], 
            "columnDefs": [
                {
                    "targets": [ 0 ],
                    "visible": true,
                    "searchable": false
                }
            ], 
            "drawCallback": function( settings ) {
                var api = this.api();
                //wrap.loaded(settings);
                loaded(settings);
            }, 
            'initComplete': function(settings, json){
                //loaded(settings);
            },
            "language" : {
                "url": "/assets/plugins/datatable_zhtw.json"
            }
        });
    }

Result in Chrome dev tool: