From f2624c272d3bcea46540937ea6bddb7d691683f0 Mon Sep 17 00:00:00 2001 From: 7PH Date: Fri, 8 Dec 2023 14:07:08 +0100 Subject: NO-JIRA Fix global error throw function to support axios response object --- server/sonar-web/src/main/js/api/rules.ts | 3 ++- server/sonar-web/src/main/js/helpers/error.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'server/sonar-web') diff --git a/server/sonar-web/src/main/js/api/rules.ts b/server/sonar-web/src/main/js/api/rules.ts index ec8c67c1563..2e49030b2ae 100644 --- a/server/sonar-web/src/main/js/api/rules.ts +++ b/server/sonar-web/src/main/js/api/rules.ts @@ -17,6 +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 { HttpStatusCode } from 'axios'; import { throwGlobalError } from '../helpers/error'; import { axiosToCatch, getJSON, post, postJSON } from '../helpers/request'; import { CleanCodeAttribute, SoftwareImpact } from '../types/clean-code-taxonomy'; @@ -79,7 +80,7 @@ export function createRule(data: CreateRuleData): Promise { return axiosToCatch.post(RULES_ENDPOINT, data).catch(({ response }) => { // do not show global error if the status code is 409 // this case should be handled inside a component - if (response && response.status === 409) { + if (response && response.status === HttpStatusCode.Conflict) { return Promise.reject(response); } return throwGlobalError(response); diff --git a/server/sonar-web/src/main/js/helpers/error.ts b/server/sonar-web/src/main/js/helpers/error.ts index bd0501b2bf5..1c4adccc358 100644 --- a/server/sonar-web/src/main/js/helpers/error.ts +++ b/server/sonar-web/src/main/js/helpers/error.ts @@ -35,5 +35,11 @@ export function throwGlobalError(param: Response | any): Promise .then(() => Promise.reject(param)); } + // Axios response object + if (param.data?.message) { + addGlobalErrorMessage(param.data?.message); + return Promise.reject(param); + } + return Promise.reject(param); } -- cgit v1.2.3