catch and finally()

This commit is contained in:
aminamos
2020-04-05 03:54:04 -07:00
parent 9c97dca644
commit 3347714e1b

View File

@@ -8,13 +8,66 @@ export function get() {
}
export function getCatch() {
axios.get("http://localhost:3000/orders/123")
.then(({data}) => {
setText(JSON.stringify(data))
})
.catch(error => setText(error))
}
export function chain() {
axios.get("http://localhost:3000/orders/1")
.then(({data}) => {
return axios.get(`http://localhost:3000/addresses/${data.shippingAddress}`)
})
.then(({data}) => {
setText(`City: ${data.city}`)
})
}
export function chainCatch() {
// axios.get("http://localhost:3000/orders/1")
// .then(({data}) => {
// axios.get(`http://localhost:3000/addresses/${data.shippingAddress}`)
// throw new Error("Error")
// })
// .catch(err => {
// setText(err);
// throw new Error("Second error")
// })
// .then(({data}) => {
// setText(`City: ${data.my.city}`)
// })
// .catch(err => setText(err))
axios.get("http://localhost:3000/orders/1")
.then(({data}) => {
return axios.get(`http://localhost:3000/addresses/${data.shippingAddress}`)
})
.then(({data}) => {
setText(`City: ${data.city}`)
})
.catch(error => setText(error))
}
export function final() {
showWaiting()
axios.get("http://localhost:3000/orders/1")
.then(({data}) => {
return axios.get(`http://localhost:3000/addresses/${data.shippingAddress}`)
})
.then(({data}) => {
setText(`City: ${data.city}`)
})
.catch(error => setText(error))
.finally(() => {
// setTimeout(() => {
// hideWaiting()
// }, 1500);
hideWaiting()
appendText(" done")
})
}