I inherited a Laravel application that is using Yajra DataTables to display grid content in a page.
If Laravel's session expires, the DataTable will throw the following alert:
DataTables warning: table id=dataTableBuilder - Ajax error. For more information about this error, please see http://datatables.net/tn/7
Viewing the Network tab in Chrome shows me that the AJAX response for the DataTable was a 401 Unauthorized. This is all expected behavior, but instead of displaying an arbitrary error to the user, I'd like to send the user to the login page with a message that says "your session timed out, please log in again." or something.
I can't figure out how to do that.
Traditional DataTables integrations allow me to pass an error handler to the AJAX response (i.e. {ajax: { error: function () {...} }}
), but there doesn't seem to be a way to do that with Laravel DataTables.
Laravel DataTables has an html()
method that I can override like so:
public function html() {
return $this->builder()
->ajax([
error => ''
]);
}
But the ajax
method on the builder doesn't allow me to pass a JavaScript handler to the error property.
Is there anyway to accomplish the force login when sessions time out?
'error' => 'window.handleDTAjaxError()'
? – Ohgodwhy