Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Wrapping axios to safely call the api without throwing exceptions
const safeApiCall = ({ url, method }) => data =>
axios({ url, method, data })
.then( result => ([null, result]) )
.catch( error => ([error, null]) );
// Partially applying the generic function above to work with the users api
const createUser = safeApiCall({
url: '/api/users',
method: 'post'
// Safely calling the api without worrying about exceptions.
const [error, user] = await createUser({
email: '',
password: 'Password'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment