Skip to content

Instantly share code, notes, and snippets.

@brybrophy
Last active October 26, 2017 20:34
Show Gist options
  • Save brybrophy/1867689b86b866ef5f23ec65464f1a7f to your computer and use it in GitHub Desktop.
Save brybrophy/1867689b86b866ef5f23ec65464f1a7f to your computer and use it in GitHub Desktop.
import axios from 'axios';
import { displayUserFeedback } from './utils';
const axiosConfig = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
timeout: 15000
};
const basePath = 'https://www.example.org/api/users';
export async function handleClickGetAllUsers() {
try {
const res = await axios.get(basePath, axiosConfig);
return res.data;
} catch () {
// This is just a hypothetical utility function to display a toast
// notification to the user in the event of an error.
displayUserFeedback('There was an error retrieving the users.');
}
}
export async function handleClickGetOneUser(userId) {
try {
const res = await axios.get(`${basePath}/${userId}`, axiosConfig);
return res.data;
} catch () {
displayUserFeedback('There was an error retrieving the user.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment