What behavior is serverSide processing returned {"error": "..."} attribute supposed to exhibit?

What behavior is serverSide processing returned {"error": "..."} attribute supposed to exhibit?

cdaringecdaringe Posts: 7Questions: 3Answers: 0

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,

  1. the returned error text isn't displayed or caught--instead my window.onerror handler executes
  2. 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

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    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.

  • cdaringecdaringe Posts: 7Questions: 3Answers: 0

    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!

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    I actually linked to that article in my post above.

    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.

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    Answer ✓

    What happens when and error parameter is found in the returned object depends upon the $.fn.dataTable.ext.errMode option. By default this is throw - which will throw an error with the error parameter's value as the message. Hence why your window.onerror event is being executed.

    It can also be alert, none or be a function 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

This discussion has been closed.