Mensa-API/src/fetch.ts
2023-12-20 14:03:16 +01:00

24 lines
459 B
TypeScript

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;
}
}