简体   繁体   中英

error while fetch data from service worker

this is my 3rd PWA project, here I have an error when fetching data from the backend but the data can still appear on the page. but in the previous project this syntax worked without any errors

fetch in service worker

self.addEventListener("fetch", event=>{
    const base_url ="https://api.football-data.org/v2/";

    if (event.request.url.indexOf(base_url) > -1) {
        event.respondWith(
            caches.open(CACHE_NAME).then(cache=>{
                return fetch(event.request).then(response=>{
                    cache.put(event.request.url, response.clone());
                    return response;
                })
            })
        );
    } else {
        event.respondWith(
            caches.match(event.request, {ignoreSearch: true}).then(response=>{
                return response || fetch (event.request);
            })
        )
    }
})

error says like this

are you sure you are sending the API auth token on the service worker fetch call?

The http request code is an error (403), maybe that's what might be going.

1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM