mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
22 lines
487 B
TypeScript
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 };
|