Arrow functions are not relevant here. The key point is the then
method on promises.
When using a promise's then
method, the first argument serves as a fulfillment handler while the second acts as a rejection handler. If the promise is fulfilled, the fulfillment value is passed to the first handler. On the other hand, if the promise is rejected, the rejection reason is passed to the second handler. Only one of these handlers will be called for a given promise, never both simultaneously.
Below is an updated snippet of the function referenced earlier in the question, featuring modified names and the removal of return true;
, which was unclear in its placement:
async check({ commit }) {
await axios.get('check')
.then(
(value) => { // ***
// Process the fulfillment value // *** fulfillment handler
}, // ***
(reason) => { // ***
// Handle the rejection // *** rejection handler
} // ***
);
});
For more information on promises, refer to the resources on MDN or the Promises A+ specification that underpins JavaScript's promise implementation.
It should be noted that making this specific function an async
function may not be necessary unless the intention is specifically to conceal any fulfillment values or rejection reasons provided by the promise handler. However, this approach achieves that, so it could serve a particular purpose in this context.