commerce/operations/fetch.ts
2023-11-18 15:50:29 -06:00

22 lines
487 B
TypeScript

async function post(path: string, payload?: any): Promise<any> {
try {
const response = await fetch(path, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ payload })
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
} catch (error) {
console.error(error);
throw new Error('HTTP Post Error');
}
}
export { post };