Async Functions

Verze:

31. 12. 2025

Zodpovědná osoba:

Dominik Šlechta

Async/await syntax MUST be used instead of Promise chains for asynchronous operations.

Async/await syntax MUST be used instead of Promise chains for asynchronous operations.

Example (Correct):

async function fetchProducts() {
    try {
        const response = await api.get('/products')
        return response.data
    } catch (error) {
        console.error('Failed to fetch products:', error)
        throw error
    }
}

Example (Incorrect):

function fetchProducts() {
    return api.get('/products').then(response => {
        return response.data
    }).catch(error => {
        console.error('Failed to fetch products:', error)
        throw error
    })
}