Spaces:
Sleeping
Sleeping
| 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; | |