I’m trying to get data from json file but even after trying multiple variarions i’m still getting promise pending error.
Code snippet as follows:
import axios from "axios";
async function getAuthorsData(){
const {authorData} = await axios.get('https://gist.githubusercontent.com/graffixnyc/a086a55e04f25e538b5d52a095fe4467/raw/e9f835e9a5439a647a24fa272fcb8f5a2b94dece/authors.json')
return authorData;
}
export const getAuthorById = async (id) => {
let trimId = id.trim();
if(typeof trimId !== 'string' || trimId == '')
throw new Error ("Please enter valid author ID.");
let authorsData = await getAuthorsData();
authorsData.forEach(author =>{
if(author.id===trimId)
return author;
else
throw new Error('author not found');
})
};
I tried various variations, still no progress. I want some output on my terminal after calling the function.