From 17453c73bc0eeab032ca66619347dee91bfec4bb Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Mon, 19 Apr 2021 14:30:09 +0200 Subject: SONAR-13737 Show descriptive error messages for GitLab PAT validation --- server/sonar-web/src/main/js/api/alm-integrations.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'server/sonar-web/src/main/js/api') diff --git a/server/sonar-web/src/main/js/api/alm-integrations.ts b/server/sonar-web/src/main/js/api/alm-integrations.ts index cc287712341..7bdd9e14622 100644 --- a/server/sonar-web/src/main/js/api/alm-integrations.ts +++ b/server/sonar-web/src/main/js/api/alm-integrations.ts @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { get, getJSON, post, postJSON } from 'sonar-ui-common/helpers/request'; +import { get, getJSON, parseError, post, postJSON } from 'sonar-ui-common/helpers/request'; import throwGlobalError from '../app/utils/throwGlobalError'; import { AzureProject, @@ -34,15 +34,17 @@ export function setAlmPersonalAccessToken(almSetting: string, pat: string): Prom return post('/api/alm_integrations/set_pat', { almSetting, pat }).catch(throwGlobalError); } -export function checkPersonalAccessTokenIsValid(almSetting: string): Promise { +export function checkPersonalAccessTokenIsValid( + almSetting: string +): Promise<{ status: boolean; error?: string }> { return get('/api/alm_integrations/check_pat', { almSetting }) - .then(() => true) - .catch((response: Response) => { + .then(() => ({ status: true })) + .catch(async (response: Response) => { if (response.status === 400) { - return false; - } else { - return throwGlobalError(response); + const error = await parseError(response); + return { status: false, error }; } + return throwGlobalError(response); }); } -- cgit v1.2.3