UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

25 lines (22 loc) 604 B
import { getErrorMessage } from '../Error'; /** * Fetch me is a wrapper around fetch that returns the response or an error message * and handles the json conversion and fetches with a POST method * @param url the url to fetch * @param data the data to send * @returns */ export const fetchMe = async (url: string, data: object) => { try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); return response; } catch (error) { return getErrorMessage(error); } };