From 194f69d190e93c76cb12b464dadb4f3d15d05734 Mon Sep 17 00:00:00 2001 From: Kiran Kumar Date: Tue, 10 Nov 2020 18:35:25 +0530 Subject: [PATCH] Async functions change from then/catch to async/await and try/catch (modern promise methods) --- examples/00-example-basic/src/api/userAPI.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/00-example-basic/src/api/userAPI.js b/examples/00-example-basic/src/api/userAPI.js index 17274bd..81f412e 100644 --- a/examples/00-example-basic/src/api/userAPI.js +++ b/examples/00-example-basic/src/api/userAPI.js @@ -1,8 +1,15 @@ import { fetchWithDelay } from './fetch'; const url = 'https://jsonplaceholder.typicode.com/users'; -const fetchUsers = () => fetchWithDelay(url); +const fetchUsers = async () =>{ +try { + const users =await fetchWithDelay(url); + return users; +} catch(error){ + throw new Error(error); +} +} export const userAPI = { fetchUsers, -}; \ No newline at end of file +};