mirror of
https://github.com/LeRoid-hub/Mensa-API.git
synced 2025-01-31 11:44:55 +00:00
24 lines
436 B
TypeScript
24 lines
436 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;
|
||
|
}
|
||
|
}
|