Skip to content

Commit

Permalink
SONAR-12245 Fix throwGlobalError and checkStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-davis-sonarsource authored and SonarTech committed Jul 29, 2019
1 parent 6fa9cf4 commit 58391f6
Show file tree
Hide file tree
Showing 18 changed files with 803 additions and 80 deletions.
2 changes: 1 addition & 1 deletion server/sonar-vsts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react": "16.8.6",
"react-dom": "16.8.6",
"regenerator-runtime": "0.13.2",
"sonar-ui-common": "0.0.14",
"sonar-ui-common": "0.0.18",
"whatwg-fetch": "2.0.4"
},
"devDependencies": {
Expand Down
18 changes: 12 additions & 6 deletions server/sonar-vsts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5849,6 +5849,11 @@ lodash@4.17.11, lodash@^4.15.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3
resolved "https://repox.jfrog.io/repox/api/npm/npm/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha1-s56mIp72B+zYniyN8SU2iRysm40=

lodash@4.17.14:
version "4.17.14"
resolved "https://repox.jfrog.io/repox/api/npm/npm/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba"
integrity sha1-nOSHrmbJYlT+ILWZ8htoFgKAeLo=

loglevel@^1.4.1:
version "1.6.3"
resolved "https://repox.jfrog.io/repox/api/npm/npm/loglevel/-/loglevel-1.6.3.tgz#77f2eb64be55a404c9fd04ad16d57c1d6d6b1280"
Expand Down Expand Up @@ -7358,7 +7363,7 @@ prop-types-exact@^1.2.0:
object.assign "^4.1.0"
reflect.ownkeys "^0.2.0"

prop-types@^15.5.10, prop-types@^15.5.6, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
prop-types@15.7.2, prop-types@^15.5.10, prop-types@^15.5.6, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
version "15.7.2"
resolved "https://repox.jfrog.io/repox/api/npm/npm/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha1-UsQedbjIfnK52TYOAga5ncv/psU=
Expand Down Expand Up @@ -8416,10 +8421,10 @@ sockjs@0.3.19:
faye-websocket "^0.10.0"
uuid "^3.0.1"

sonar-ui-common@0.0.14:
version "0.0.14"
resolved "https://repox.jfrog.io/repox/api/npm/npm/sonar-ui-common/-/sonar-ui-common-0.0.14.tgz#56faa2ba62503c206e9894f55f36bd9ff4934257"
integrity sha1-VvqiumJQPCBumJT1Xza9n/STQlc=
sonar-ui-common@0.0.18:
version "0.0.18"
resolved "https://repox.jfrog.io/repox/api/npm/npm/sonar-ui-common/-/sonar-ui-common-0.0.18.tgz#93b71859f83b85cc23e8c201bb9ed0420fcbb479"
integrity sha1-k7cYWfg7hcwj6MIBu57QQg/LtHk=
dependencies:
"@types/react-select" "1.2.6"
classnames "2.2.6"
Expand All @@ -8433,7 +8438,8 @@ sonar-ui-common@0.0.14:
date-fns "1.30.1"
formik "1.2.0"
history "3.3.0"
lodash "4.17.11"
lodash "4.17.14"
prop-types "15.7.2"
react-draggable "3.2.1"
react-intl "2.8.0"
react-modal "3.8.2"
Expand Down
2 changes: 1 addition & 1 deletion server/sonar-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"regenerator-runtime": "0.13.2",
"remark-custom-blocks": "2.3.0",
"remark-slug": "5.1.0",
"sonar-ui-common": "0.0.14",
"sonar-ui-common": "0.0.18",
"unist-util-visit": "1.4.0",
"valid-url": "1.0.9",
"whatwg-fetch": "2.0.4"
Expand Down
6 changes: 3 additions & 3 deletions server/sonar-web/src/main/js/api/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export function isValidLicense(): Promise<{ isValidLicense: boolean }> {
}

export function showLicense(): Promise<License> {
return getJSON('/api/editions/show_license').catch((e: { response: Response }) => {
if (e.response && e.response.status === 404) {
return getJSON('/api/editions/show_license').catch((response: Response) => {
if (response && response.status === 404) {
return Promise.resolve(undefined);
}
return throwGlobalError(e);
return throwGlobalError(response);
});
}
35 changes: 8 additions & 27 deletions server/sonar-web/src/main/js/api/quality-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@
*/
import { map } from 'lodash';
import { csvEscape } from 'sonar-ui-common/helpers/csv';
import {
checkStatus,
getJSON,
parseJSON,
post,
postJSON,
request,
RequestData
} from 'sonar-ui-common/helpers/request';
import { getJSON, post, postJSON, RequestData } from 'sonar-ui-common/helpers/request';
import throwGlobalError from '../app/utils/throwGlobalError';

export interface ProfileActions {
Expand Down Expand Up @@ -89,23 +81,11 @@ export function getQualityProfile(data: {
}

export function createQualityProfile(data: RequestData): Promise<any> {
return request('/api/qualityprofiles/create')
.setMethod('post')
.setData(data)
.submit()
.then(checkStatus)
.then(parseJSON)
.catch(throwGlobalError);
return postJSON('/api/qualityprofiles/create', data).catch(throwGlobalError);
}

export function restoreQualityProfile(data: RequestData): Promise<any> {
return request('/api/qualityprofiles/restore')
.setMethod('post')
.setData(data)
.submit()
.then(checkStatus)
.then(parseJSON)
.catch(throwGlobalError);
return postJSON('/api/qualityprofiles/restore', data).catch(throwGlobalError);
}

export interface ProfileProject {
Expand All @@ -125,7 +105,7 @@ export function getProfileInheritance(profileKey: string): Promise<any> {
return getJSON('/api/qualityprofiles/inheritance', { profileKey }).catch(throwGlobalError);
}

export function setDefaultProfile(profileKey: string): Promise<void> {
export function setDefaultProfile(profileKey: string) {
return post('/api/qualityprofiles/set_default', { profileKey });
}

Expand All @@ -142,9 +122,10 @@ export function deleteProfile(profileKey: string) {
}

export function changeProfileParent(profileKey: string, parentKey: string) {
return post('/api/qualityprofiles/change_parent', { profileKey, parentKey }).catch(
throwGlobalError
);
return post('/api/qualityprofiles/change_parent', {
profileKey,
parentKey
}).catch(throwGlobalError);
}

export function getImporters(): Promise<
Expand Down
8 changes: 4 additions & 4 deletions server/sonar-web/src/main/js/api/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ export function createRule(data: {
}): Promise<T.RuleDetails> {
return postJSON('/api/rules/create', data).then(
r => r.rule,
error => {
response => {
// do not show global error if the status code is 409
// this case should be handled inside a component
if (error && error.response && error.response.status === 409) {
return Promise.reject(error.response);
if (response && response.status === 409) {
return Promise.reject(response);
} else {
return throwGlobalError(error);
return throwGlobalError(response);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import DuplicationsRating from 'sonar-ui-common/components/ui/DuplicationsRating
import Level from 'sonar-ui-common/components/ui/Level';
import Rating from 'sonar-ui-common/components/ui/Rating';
import { formatMeasure } from 'sonar-ui-common/helpers/measures';
import * as request from 'sonar-ui-common/helpers/request';
import NotFound from '../../../app/components/NotFound';
import Favorite from '../../../components/controls/Favorite';
import HomePageSelect from '../../../components/controls/HomePageSelect';
Expand Down Expand Up @@ -92,6 +91,7 @@ import addGlobalSuccessMessage from '../../utils/addGlobalSuccessMessage';
import throwGlobalError from '../../utils/throwGlobalError';
import A11ySkipTarget from '../a11y/A11ySkipTarget';
import Suggestions from '../embed-docs-modal/Suggestions';
import request from './legacy/request-legacy';

const exposeLibraries = () => {
const global = window as any;
Expand Down
Loading

0 comments on commit 58391f6

Please sign in to comment.