/
AchDoA
/
lab
Обзор
Документация
Войти
/
AchDoA
/
lab
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
module_2.1/fetch_users.js
19 строк
684 B
AoDhcA
Add fetch_users.js: Implement a new module for fetching user data.
28 мар 2026, 20:21
28 мар 2026, 20:21
e06e59d
Код
Авторство
О чём код?
/** * Fetches list of users from JSONPlaceholder and returns their names. * @returns {Promise<string[]>} Array of user names * @throws {Error} If network request fails or response is not ok */ async function fetchUsers() { try { const response = await fetch('https://jsonplaceholder.typicode.com/users'); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const users = await response.json(); return users.map(user => user.name); } catch (error) { console.error('Failed to fetch users:', error); // Re-throw to let the caller handle it (or return [] if preferred) throw error; } }