What behavior is serverSide processing returned {"error": "..."} attribute supposed to exhibit?
What behavior is serverSide processing returned {"error": "..."} attribute supposed to exhibit?
Hi Allan, all:
In the manual, it specifies to set an 'error'
property on serverSide data returned in order to display some error text to the user.
How is specifying the "error" attr supposed to work? For example, if there is an error, I return the error prop:
{
"draw": null,
"recordsTotal": null,
"recordsFiltered": null,
"data": [],
"dev": [],
"error": "server error occurred. the error has been logged"
}
However,
- the returned error text isn't displayed or caught--instead my
window.onerror
handler executes - the
'Processing'
text remains on the screen
Is an in-table modal supposed to appear? I can pass my own error handler to the ajax: { ... config ... } described here in my ajax definition. This is fine, although, the 'error'
text isn't piped through either.
Just looking for clarity! I'm willing to update the docs via PR for any tips provided! I don't have access to an open API, hence no demo supplied. If you know an open API that I can hit, I will make a mockup as needed.
This question has an accepted answers - jump to answer
Answers
I haven't done this myself, but I was curious and searched the forum. This thread:
https://www.datatables.net/forums/discussion/14841/how-to-catch-response-of-server-side-processing-if-error-occurs
gives two solutions depending on DT version.
If you fix this I'd be interested to see exactly how.
hey @tangerine. I actually linked to that article in my post above. I do use 1.10.x. There's still an information disconnect, however, on how that 'error' attr makes it to the error handler function, if it's even supposed to at all. Appreciate the effort!
Doh! How did I miss that...?.
I take your point - if something more complex than a js alert is required, or we want to return a specific error message rather than the generic one - then what? Perhaps Allan can give further hints.
What happens when and
error
parameter is found in the returned object depends upon the$.fn.dataTable.ext.errMode
option. By default this isthrow
- which will throw an error with theerror
parameter's value as the message. Hence why yourwindow.onerror
event is being executed.It can also be
alert
,none
or be afunction
which will execute (so you could show a custom dialogue box to your users for example).I need to document this better! I'm going to add a list of static configuration options to the reference guide.
Allan