+ Start a Discussion

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.


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">

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

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