+ Start a Discussion
LWCLWC 

Show Error Message in place of spinner when data load fails through connectedcallback

Hi Guys,

I am making a integration callout through connectedcallback function during that time i need to show spinner until data gets loaded this part i am able to do but in case on negative senario when i get no response i need to stop showing spinner and show error with error icon can you please help how to achive this functionality.



 
AbhinavAbhinav (Salesforce Developers) 
Please share related code as well so that community can help you better.

Thanks!
GulshanRajGulshanRaj
Hi,

You can use the following code to achieve this.

First add spinner to lwc component
<div class="spinner">
    <template if:true={isLoading}>
         <lightning-spinner alternative-text="Loading" variant="brand" size="large">
         </lightning-spinner>
    </template>
</div>

And then add your logic inside the catch block.
@track isLoading = false;
    handleDataLoad() {
        this.isLoading = true;
        populateData()
            .then(result => {
                // code for positive scenario
            })
            .catch(error => {
                this.isLoading = false;
                /// code for negative scenario
            });
    }


Thanks
Gulshan Raj (https://www.linkedin.com/in/gulshan-raj/)