Mensa-API/src/fetch.ts

24 lines
436 B
TypeScript
Raw Normal View History

2023-12-19 01:37:22 +00:00
import axios from 'axios';
const isUrl = (url: string) => {
try {
new URL(url);
return true;
} catch (err) {
return false;
}
}
export default async function fetch(url: string) {
if (!isUrl(url)) {
throw new Error('Invalid URL');
}
try {
const res = await axios.get(url)
return res.data;
} catch (err) {
console.log(err);
return null;
}
}