diff --git a/.circleci/config.yml b/.circleci/config.yml index 0e161844..e8eac28e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,7 @@ jobs: - attach_workspace: at: . - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc - - run: npm publish + - run: npm publish --tag test-release # dont change anything workflows: version: 2 diff --git a/package.json b/package.json index 8435779d..578a2041 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "1.1.0", + "version": "1000.25.1", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0", diff --git a/src/actions/auth.js b/src/actions/auth.js index f81b62f9..d65f0cfe 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -6,6 +6,30 @@ import { createActions } from 'redux-actions'; import { decodeToken } from '@topcoder-platform/tc-auth-lib'; import { getApiV3, getApiV5 } from '../services/api'; +import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors'; + +/** + * Helper method that checks for HTTP error response v5 and throws Error in this case. + * @param {Object} res HTTP response object + * @return {Object} API JSON response object + * @private + */ +async function checkErrorV5(res) { + if (!res.ok) { + if (res.status === 403) { + setErrorIcon(ERROR_ICON_TYPES.API, 'Auth0', res.statusText); + } + throw new Error(res.statusText); + } + const jsonRes = (await res.json()); + if (jsonRes.message) { + throw new Error(res.message); + } + return { + result: jsonRes, + headers: res.headers, + }; +} /** * @static @@ -22,8 +46,7 @@ function loadProfileDone(userTokenV3) { apiV3.get(`/members/${user.handle}`) .then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : {})), apiV5.get(`/groups?memberId=${user.userId}&membershipType=user`) - .then(res => (res.ok ? res.json() : new Error(res.statusText))) - .then(res => (res.message ? new Error(res.message) : res)), + .then(checkErrorV5).then(res => res.result || []), ]).then(([profile, groups]) => ({ ...profile, groups })); }