I have a website that enables users to search for their favourite author from the Goodreads API.
The following useEffect is an example of how the data is obtained:
useEffect(() => {
const abortController = new AbortController();
let apiKey = "example_API_key";
const fetchData = async () => {
const result = await axios(
` https://vast-crag-56368.herokuapp.com/https://www.goodreads.com/search/index.xml?key=${apiKey}&q=${author}`
);
let books = "";
let array = [];
let filteredData = [];
const xml = result.data;
parseString(xml, function (err, result) {
books = result.GoodreadsResponse.search[0].results[0].work;
if (books) {
for (let i = 0; i < books.length; i++) {
array.push({
author2: books[i].best_book[0].author[0].name[0],
authorId: books[i].best_book[0].author[0].id[0]._,
});
}
}
});
filteredData = array.filter((x) => x.author2 === author);
try {
setAuthy(filteredData[0].authorId);
} catch {
setError("error");
}
};
fetchData();
}, [search]);
As you can see I am using a custom cors-anywhere domain. The website was working fine but is now failing to retrieve any data. I now get this error:
"Failed to load resource: the server responded with a status of 404 (Not Found)"
Would greatly appreciate any advice on how I can prevent this from happening.
Let me know if you need any more info.
Thanks,
Dan
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…