diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/code/actions/index.js')
-rw-r--r-- | server/sonar-web/src/main/js/apps/code/actions/index.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/server/sonar-web/src/main/js/apps/code/actions/index.js b/server/sonar-web/src/main/js/apps/code/actions/index.js index a68df6429b7..53437e244c8 100644 --- a/server/sonar-web/src/main/js/apps/code/actions/index.js +++ b/server/sonar-web/src/main/js/apps/code/actions/index.js @@ -26,6 +26,7 @@ export const SEARCH = 'SEARCH'; export const UPDATE_QUERY = 'UPDATE_QUERY'; export const START_FETCHING = 'START_FETCHING'; export const STOP_FETCHING = 'STOP_FETCHING'; +export const RAISE_ERROR = 'RAISE_ERROR'; export function initComponentAction (component, breadcrumbs = []) { @@ -67,6 +68,13 @@ export function stopFetching () { return { type: STOP_FETCHING }; } +export function raiseError (message) { + return { + type: RAISE_ERROR, + message + }; +} + function getPath (componentKey) { return '/' + encodeURIComponent(componentKey); @@ -107,6 +115,22 @@ let requestTree = (query, baseComponent, dispatch) => { }; requestTree = _.debounce(requestTree, 250); +async function getErrorMessage (response) { + switch (response.status) { + case 401: + return window.t('not_authorized'); + default: + try { + let json = await response.json(); + return json['err_msg'] || + (json.errors && _.pluck(json.errors, 'msg').join('. ')) || + window.t('default_error_message'); + } catch (e) { + return window.t('default_error_message'); + } + } +} + export function initComponent (componentKey, breadcrumbs) { return dispatch => { dispatch(startFetching()); @@ -125,7 +149,11 @@ export function browse (componentKey) { dispatch(browseAction(component, children, breadcrumbs)); }) .then(() => dispatch(pushPath(getPath(componentKey)))) - .then(() => dispatch(stopFetching())); + .then(() => dispatch(stopFetching())) + .catch(e => { + getErrorMessage(e.response) + .then(message => dispatch(raiseError(message))); + }); }; } |