From d3c1e2e7ab7165722aa70c57830841a15454bb77 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" <contato@luizrrodrigues.com.br> Date: Wed, 4 Nov 2020 07:29:31 -0300 Subject: [PATCH 1/3] Auth - Added API V5 response --- src/actions/auth.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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 })); } From c818f2090189b22a56a885cb4b6902a03f950df8 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" <contato@luizrrodrigues.com.br> Date: Wed, 4 Nov 2020 07:35:10 -0300 Subject: [PATCH 2/3] Auth0 hotfix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 595ff22b1b0d1cfc76b3bd31612c5cb6ae8d465a Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" <contato@luizrrodrigues.com.br> Date: Wed, 4 Nov 2020 07:35:26 -0300 Subject: [PATCH 3/3] ci: added dist tag --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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