I have the following code
const result = fetch(`link`${id})
.then(response => response.json())
.then(data => {
let link;
if (data && data.url) {
link = data.url.href;
}
return fetch(link);
})
.then(response => response.json())
.catch(() => {
//do something
});
result
.then(data => {
let link;
if (data && data.url1) {
link = data.url1.href;
}
return fetch(link);
})
.then(response => response.json())
I'm making the call to the const result = fetch('link')
and result.then
depends on the result of the result
.
But for some ids
the original fetch is returned with error and I'm doing something in catch for that.
The question is how can I stop the next then on result
so that If it returned with error the extra request won't be made? (because this request only causes an error)