Created
November 19, 2019 17:37
-
-
Save nachodd/56e19337f7ada4ea2434451f493d0935 to your computer and use it in GitHub Desktop.
api calls example, returning promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// '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