Spaces:
Sleeping
Sleeping
File size: 664 Bytes
819bacd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import baseUrl from "../api.config";
const postData = async (url, data) => {
const formData = new URLSearchParams();
for (const key in data) {
formData.append(key, data[key]);
}
const response = await fetch(baseUrl + url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: formData.toString(),
});
if (!response.ok) {
const errorData = await response.json();
const error = new Error("HTTP error");
error.status = response.status;
error.detail = errorData.detail || "Something went wrong";
throw error;
}
return response.json();
};
export default postData;
|