Skip to content

Commit

Permalink
Updated geostore error parser location
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap committed Jan 12, 2018
1 parent b408315 commit 63dcfbf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
19 changes: 19 additions & 0 deletions web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,25 @@ var Api = {
postUser.attribute = postUser.attribute && postUser.attribute.length > 0 ? [...postUser.attribute, uuidAttr] : [uuidAttr];
return postUser;
}
},
errorParser: {
/**
* Returns localized message for geostore map errors
* @param {object} e error object
* @return {object} {title, message}
*/
mapsError: e => {
if (e.status === 403 || e.status === 404 || e.status === 409 || e.status === 500) {
return {
title: 'map.mapError.errorTitle',
message: 'map.mapError.error' + e.status
};
}
return {
title: 'map.mapError.errorTitle',
message: 'map.mapError.errorDefault'
};
}
}
};

Expand Down
11 changes: 11 additions & 0 deletions web/client/api/__tests__/GeoStoreDAO-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ describe('Test correctness of the GeoStore APIs', () => {
const user2 = API.utils.initUser(originalUser2);
expect(user2.attribute.length).toBe(2);
});

it('test error parser', () => {
expect(API.errorParser.mapsError({status: 409})).toEqual({
title: 'map.mapError.errorTitle',
message: 'map.mapError.error409'
});
expect(API.errorParser.mapsError({status: 400})).toEqual({
title: 'map.mapError.errorTitle',
message: 'map.mapError.errorDefault'
});
});
});
24 changes: 8 additions & 16 deletions web/client/utils/LocaleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,12 @@ const DATE_FORMATS = {
"nl-NL": "dd/MM/yyyy"
};

const errorParser = {
geostore: {
mapsError: e => {
if (e.status === 403 || e.status === 404 || e.status === 409 || e.status === 500) {
return {
title: 'map.mapError.errorTitle',
message: 'map.mapError.error' + e.status
};
}
return {
title: 'map.mapError.errorTitle',
message: 'map.mapError.errorDefault'
};
}
}
const servicesErrorParser = {
geostore: require('../api/GeoStoreDAO').errorParser
};

const getErrorParser = service => {
return servicesErrorParser[service];
};
/**
* Utilities for locales.
Expand Down Expand Up @@ -137,7 +128,8 @@ const LocaleUtils = {
* @return {object} {title, message}
*/
getErrorMessage: (e, service, section) => {
return service && section && errorParser[service] && errorParser[service][section] && errorParser[service][section](e) || {
const errorParser = getErrorParser(service);
return service && section && errorParser && errorParser[section] && errorParser[section](e) || {
title: 'errorTitleDefault',
message: 'errorDefault'
};
Expand Down

0 comments on commit 63dcfbf

Please sign in to comment.