try catch

This commit is contained in:
Feruz M 2018-12-19 14:16:18 +02:00 committed by GitHub
parent 06c4668eb5
commit 7dd9b6cfc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,8 +50,15 @@ export const Login = (username, password) => {
resultKeys[pubKey] = publicKeys[pubKey];
}
});
const jsonMetadata = JSON.parse(account.json_metadata);
let jsonMetadata;
try {
jsonMetadata = JSON.parse(account.json_metadata);
}
catch(err) {
jsonMetadata = '';
//TODO: handle wrong json format properly
//reject(new Error(err));
}
if (Object.keys(jsonMetadata).length !== 0) {
avatar = jsonMetadata.profile.profile_image || '';
}
@ -76,14 +83,14 @@ export const Login = (username, password) => {
updateCurrentUsername(account.name);
})
.catch(() => {
reject(new Error('Invalid credentails, please check and try again'));
reject(new Error('Invalid credentials, please check and try again'));
});
} else {
reject(new Error('Invalid credentails, please check and try again'));
reject(new Error('Invalid credentials, please check and try again'));
}
})
.catch(() => {
reject(new Error('Invalid credentails, please check and try again'));
reject(new Error('Invalid credentials, please check and try again'));
});
});
};
@ -100,7 +107,7 @@ export const loginWithSC2 = async (accessToken) => {
avatar = jsonMetadata.profile.profile_image;
}
} catch (error) {
reject(new Error('Invalid credentails, please check and try again'));
reject(new Error('Invalid credentials, please check and try again'));
}
const userData = {
username: account.account.name,