Skip to content

Commit

Permalink
Move back to async/await instead of promise
Browse files Browse the repository at this point in the history
  • Loading branch information
dopecodez committed Jun 3, 2023
1 parent 7c97f49 commit b5293c3
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions source/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ let API_URL = 'https://en.wikipedia.org/w/api.php?',
// RATE_LIMIT_LAST_CALL = undefined,
const USER_AGENT = 'wikipedia (https://github.com/dopecodez/Wikipedia/)';

function callAPI(url: string) {
const options: AxiosRequestConfig = {
headers: {
'Api-User-Agent': USER_AGENT
}
};

return axios.get(url, options)
.then(response => {
return response;
})
.then(response => response.data)
.catch(error => {
throw new wikiError(error);
});
async function callAPI(url: string) {
const options: AxiosRequestConfig = {
headers: {
"Api-User-Agent": USER_AGENT,
},
};
try {
const { data } = await axios.get(url, options);
return data;
} catch (error) {
throw new wikiError(error);
}
}

// Makes a request to legacy php endpoint
Expand Down

0 comments on commit b5293c3

Please sign in to comment.