akf-forum/public/js/request.js

19 lines
424 B
JavaScript
Raw Normal View History

2022-08-11 01:36:53 +03:00
export default async function request(link, method = "POST", body={}) {
try {
const res = await fetch(link, {
method,
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json"
}
}).then(res => res.json())
if (res.error) return alert(res.error);
2022-08-11 01:36:53 +03:00
return res;
} catch (err) {
alert(err);
}
}