Skip to content

Instantly share code, notes, and snippets.

@nachodd
Created November 19, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nachodd/56e19337f7ada4ea2434451f493d0935 to your computer and use it in GitHub Desktop.
Save nachodd/56e19337f7ada4ea2434451f493d0935 to your computer and use it in GitHub Desktop.
api calls example, returning promise
// 'request' it's an axios instance, that it has a request interceptor setted on it (to add an auth header)
// This is all done in utils/request.js. So that all api calls made with 'request' had auth header setted on it
import request from "utils/request"
export function getResponsabilities(userId) {
return new Promise(async (resolve, reject) => {
try {
const res = await request({
url: `v1/f12/${userId}/responsabilities`,
method: "get",
})
// return only the data needed. Also, it could be done using: _.get(res, "data.data", "DEFAULT_VALUE") from lodash
if (res && res.data && res.data.data) {
resolve(res.data.data)
} else {
reject("Error fetching Responsabilities")
}
} catch (e) {
// maybe log the error?
reject(e)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment