Skip to content

Commit bf0b718

Browse files
committed
chore: extend error check to first and last characters and adjust error statement
1 parent 8b8a887 commit bf0b718

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/base_service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,24 @@ function usesBasicForIam(obj: any): boolean {
8989
return obj.username === 'apikey' && !obj.password.startsWith('icp-');
9090
}
9191

92-
// returns true if the string has a { or " as the first character
92+
// returns true if the string has a curly bracket or quote as the first or last character
9393
// these are common user-issues that we should handle before they get a network error
94-
function badFirstChar(value: string): boolean {
95-
return value.startsWith('{') || value.startsWith('"');
94+
function badCharAtAnEnd(value: string): boolean {
95+
return value.startsWith('{') || value.startsWith('"') || value.endsWith('{') || value.endsWith('"');
9696
}
9797

98-
// checks credentials for common user mistakes of copying { or " characters from the documentation
98+
// checks credentials for common user mistakes of copying {, }, or " characters from the documentation
9999
function checkCredentials(obj: any) {
100100
let errorMessage = '';
101101
const credsToCheck = ['url', 'username', 'password', 'iam_apikey'];
102102
credsToCheck.forEach(cred => {
103-
if (obj[cred] && badFirstChar(obj[cred])) {
104-
errorMessage += `${cred} starts with a bad character. `;
103+
if (obj[cred] && badCharAtAnEnd(obj[cred])) {
104+
errorMessage += `The ${cred} shouldn't start or end with curly brackets or quotes. Be sure to remove any {, }, or "`;
105105
}
106106
});
107107

108108
if (errorMessage.length) {
109-
errorMessage += 'Revise these credentials - they should not start with a { or "';
109+
errorMessage += 'Revise these credentials - they should not start or end with curly brackets or quotes.';
110110
return errorMessage;
111111
} else {
112112
return null;

0 commit comments

Comments
 (0)