Skip to content

Commit

Permalink
Added safe JSON parse in manager (#348)
Browse files Browse the repository at this point in the history
* Added safe JSON parse in the locales of use in manager

* [skip ci] Update versioning file

Co-authored-by: wilian <wilian.silva@zup.com.br>
  • Loading branch information
lucasbrunozup and wiliansilvazup authored Feb 19, 2021
1 parent 582a366 commit 6cf6c0e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion horusec-manager/.semver.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
alpha: 0
beta: 0
rc: 0
release: v1.7.2
release: v1.7.3
11 changes: 6 additions & 5 deletions horusec-manager/src/helpers/localStorage/currentLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import { localStorageKeys } from 'helpers/enums/localStorageKeys';
import { Language } from 'helpers/interfaces/Language';

const getCurrentLanguage = (): Language | null => {
const localData: Language = JSON.parse(
window.localStorage.getItem(localStorageKeys.LANGUAGE)
);

return localData;
try {
const localData = window.localStorage.getItem(localStorageKeys.LANGUAGE);
return localData ? JSON.parse(localData) : null;
} catch (e) {
return null;
}
};

const setCurrentLanguage = (value: Language) => {
Expand Down
11 changes: 6 additions & 5 deletions horusec-manager/src/helpers/localStorage/currentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import { User } from 'helpers/interfaces/User';
import { getCurrentConfig } from './horusecConfig';

const getCurrentUser = (): User | null => {
const localData: User = JSON.parse(
window.localStorage.getItem(localStorageKeys.USER)
);

return localData;
try {
const localData = window.localStorage.getItem(localStorageKeys.USER);
return localData ? JSON.parse(localData) : null;
} catch (e) {
return null;
}
};

const setCurrentUser = (value: User) => {
Expand Down
12 changes: 8 additions & 4 deletions horusec-manager/src/helpers/localStorage/horusecConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ import { localStorageKeys } from 'helpers/enums/localStorageKeys';
import { HorusecConfig } from 'helpers/interfaces/HorusecConfig';

const initialValues: HorusecConfig = {
authType: null,
authType: 'horusec',
applicationAdminEnable: false,
disabledBroker: false,
disabledBroker: true,
};

const getCurrentConfig = (): HorusecConfig => {
const config = window.localStorage.getItem(localStorageKeys.CONFIG);
return config ? JSON.parse(config) : initialValues;
try {
const config = window.localStorage.getItem(localStorageKeys.CONFIG);
return config ? JSON.parse(config) : initialValues;
} catch (e) {
return initialValues;
}
};

const setCurrenConfig = (value: HorusecConfig) => {
Expand Down

0 comments on commit 6cf6c0e

Please sign in to comment.