Material-table: Issue with Promise.reject()

Created on 21 Jun 2019  路  7Comments  路  Source: mbrn/material-table

Hi!
I am trying to add some issue handlers in my table. In remote data Promise I want to use reject, when something will go wrong (according to documentation and tips from other issues).
It's not working correctly tho. I am getting error: _Uncaught (in promise) undefined_.
In the same place resolve (with proper data ofc) is working great.

Unfortunately it doesn't say much, so I have no clue where to look for the error.

Have you ever encounter similar issue?

bug

Most helpful comment

Hi any updates on this? also having this issue on handling errors.

All 7 comments

Ideally you should to show the part of your code that is giving error to a accurate answer.
Even so, a possible solution, make sure that you are using .then and .catch correctly.

https://stackoverflow.com/questions/53015074/then-uncaught-in-promise-this-is-undefined
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch

Thank's for quick answer!
Sure, code would be useful :) I am pasting it below.

I tried to find answers using docs you suggested - unfortunately without success.

```javascript

          data={query =>
            new Promise((resolve, reject) => {
              axios
                .get(url)
                .then(result => {
                  let data = this.buildTableData(result.data.content);
                  resolve({
                    data,
                    page: result.data.pageable.pageNumber,
                    totalCount: result.data.totalElements
                  });
                })
                .catch(error => {
                    reject(); //not working here
                });
            })
          }

````

Hi @JKrymarys ,

I will look at this asap. Someone else reported this problem.

Hi any updates on this? also having this issue on handling errors.

+1

Does anyone have resolve???
I don't know why but after error my table is fixed in loading state.
How could escape from this state?

 queryPromise = (query) => new Promise((resolve, reject) => {

        myRequest(query, params)
        .then((response) => {
            //work OK
            this.setState((state, props) => {
                resolve({
                    data: response.data.Data,
                    page: 0,
                    totalCount: response.data.Total,
                  });
            });
        })
        .catch(error => {
            reject(); //not working here
        });

    }).catch(error =>{}); 

Table appears like this:
Screenshot from 2020-01-23 10-50-59

Instead of reject();, you could return an empty dataset:
resolve({data: [], page: 0, totalCount: 0});
But this is just a temporary solution ...

Was this page helpful?
0 / 5 - 0 ratings