diff options
author | 7PH <benjamin.raymond@sonarsource.com> | 2023-12-08 14:07:08 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-12-08 20:03:05 +0000 |
commit | f2624c272d3bcea46540937ea6bddb7d691683f0 (patch) | |
tree | dfab3d77dc12dfc88c8cbcc0c1d032eacc35e680 /server/sonar-web | |
parent | 5ed270ff91f07132ac004af022b0d4b5b441fcf7 (diff) | |
download | sonarqube-f2624c272d3bcea46540937ea6bddb7d691683f0.tar.gz sonarqube-f2624c272d3bcea46540937ea6bddb7d691683f0.zip |
NO-JIRA Fix global error throw function to support axios response object
Diffstat (limited to 'server/sonar-web')
-rw-r--r-- | server/sonar-web/src/main/js/api/rules.ts | 3 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/helpers/error.ts | 6 |
2 files changed, 8 insertions, 1 deletions
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<RestRuleDetails> { return axiosToCatch.post<RuleDetails>(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<Response | any> .then(() => Promise.reject(param)); } + // Axios response object + if (param.data?.message) { + addGlobalErrorMessage(param.data?.message); + return Promise.reject(param); + } + return Promise.reject(param); } |