material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Issue with Promise.reject()

Open JKrymarys opened this issue 7 years ago • 7 comments

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?

JKrymarys avatar Jun 21 '19 09:06 JKrymarys

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

AugustoCalaca avatar Jun 21 '19 12:06 AugustoCalaca

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.


              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
                    });
                })
              }

JKrymarys avatar Jun 21 '19 12:06 JKrymarys

Hi @JKrymarys ,

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

mbrn avatar Jul 02 '19 05:07 mbrn

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

iamrenzx avatar Oct 17 '19 04:10 iamrenzx

+1

imnaveenk avatar Jan 20 '20 06:01 imnaveenk

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

ambr89 avatar Jan 23 '20 08:01 ambr89

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

Freenex1911 avatar Mar 14 '20 23:03 Freenex1911