My API.js contains following, I am using Laravel 5 , I need to handle CSRF TokenMismatchException as well for which I am using Exception/handler.phpAm I doing this right?  I am replacing $.ajax in each of my js files to API.callHow would you handle/create something like following?  Actually code is working, but what about existing error callbacks I am having in my other js files, because I am replacing it with error specified in API.call method (look at API.call method below).  Is there any existing library available for this kind of thing?  function API() {}API.defaultOptions = {    url: '',    type: '',    data: {},    headers: {        'X-CSRF-TOKEN': $('meta[name=csrf-token]').attr('content')    },    dataType: 'json',    success: function (res) {    },    error: function (res) {    }}API.get = function (setup) {    setup.type = 'GET';    API.call(setup);}API.post = function (setup) {    setup.type = 'POST';    API.call(setup);}API.put = function (setup) {    setup.type = 'PUT';    API.call(setup);}API.patch = function (setup) {    setup.type = 'PATCH';    API.call(setup);}API.delete = function (setup) {    setup.type = 'DELETE';    API.call(setup);}API.call = function (setup) {    var request = $.extend(API.defaultOptions, setup);    request.error = function (res) {        if (res.status == 400 && res.responseJSON.msg) {            toastr.showError(res.responseJSON.msg);        }    }    $.ajax(request);}
Dispatcher for calling Laravel REST API
javascript;jquery;ajax;rest