Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle html maintenance message #814

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/shared/orgListUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,10 @@ export class OrgListUtil {
await org.refreshAuth();
return 'Connected';
} catch (err) {
const error = err as SfError;
const logger = await OrgListUtil.retrieveLogger();
logger.trace(`error refreshing auth for org: ${org.getUsername()}`);
logger.trace(error);
return (error.code ?? error.message) as string;
return authErrorHandler(err, org.getUsername() as string);
}
} catch (err) {
const error = err as SfError;
const logger = await OrgListUtil.retrieveLogger();
logger.trace(`error refreshing auth for org: ${username}`);
logger.trace(error);
return (error.code ?? error.message ?? 'Unknown') as string;
return authErrorHandler(err, username);
}
}
}
Expand Down Expand Up @@ -377,3 +369,15 @@ const removeRestrictedInfoFromConfig = (
const sandboxFilter = (org: AuthFieldsFromFS): boolean => Boolean(org.isSandbox);
const regularOrgFilter = (org: AuthFieldsFromFS): boolean => !org.isSandbox && !org.isDevHub;
const devHubFilter = (org: AuthFieldsFromFS): boolean => Boolean(org.isDevHub);

const authErrorHandler = async (err: unknown, username: string): Promise<string> => {
const error = err as SfError;
const logger = await OrgListUtil.retrieveLogger();
logger.trace(`error refreshing auth for org: ${username}`);
logger.trace(error);
// Orgs under maintenace return html as the error message.
if (error.message.includes('maintenance')) return 'Down (Maintenance)';
// handle other potential html responses
if (error.message.includes('<html>')) return 'Bad Response';
return (error.code ?? error.message) as string;
};
27 changes: 27 additions & 0 deletions test/shared/orgListUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,33 @@ describe('orgListUtil tests', () => {
expect(checkNonScratchOrgIsDevHub.called).to.be.false;
});

it('handles html responses for non-scratch orgs under maintenance', async () => {
determineConnectedStatusForNonScratchOrg.restore();
stubMethod(sandbox, Org, 'create').returns(Org.prototype);
stubMethod(sandbox, Org.prototype, 'getField').returns(undefined);
stubMethod(sandbox, Org.prototype, 'getUsername').returns(devHubConfigFields.username);
stubMethod(sandbox, Org.prototype, 'refreshAuth').rejects({
message: `<html>
<body>
<center>
<table bgcolor="white" cellpadding="0" cellspacing="0" width="758">
<tbody>
<tr>
<td><span style="font-family: Verdana; font-size: medium; font-weight: bold;">We are down for maintenance.</span><br><br>Sorry for the inconvenience. We'll be back shortly.</td><br>
</tr>
</tbody>
</table>
</center>
</body>
</html>`,
});

const orgGroups = await OrgListUtil.readLocallyValidatedMetaConfigsGroupedByOrgType(fileNames, false);
expect(orgGroups.nonScratchOrgs).to.have.length(1);
expect(orgGroups.nonScratchOrgs[0].connectedStatus).to.equal('Down (Maintenance)');
expect(checkNonScratchOrgIsDevHub.called).to.be.false;
});

it('handles auth file problems for non-scratch orgs', async () => {
determineConnectedStatusForNonScratchOrg.restore();
stubMethod(sandbox, Org, 'create').rejects({ message: 'bad file' });
Expand Down