< Summary - Envilder Node.js SDK

Information
Class: src/sdks/nodejs/src/domain/sso-session-expired-error.ts
Assembly: Default
File(s): src/sdks/nodejs/src/domain/sso-session-expired-error.ts
Tag: 427_29134414720
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 43
Line coverage: 100%
Branch coverage
100%
Covered branches: 7
Total branches: 7
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/sdks/nodejs/src/domain/sso-session-expired-error.ts

#LineLine coverage
 1/**
 2 * Thrown when the AWS SSO session for the active profile could not be loaded
 3 * or has expired, so credentials cannot be resolved.
 4 */
 5export class SsoSessionExpiredError extends Error {
 6  readonly profileName?: string;
 7  readonly cause?: unknown;
 8
 9  constructor(profileName?: string, cause?: unknown) {
 610    super(SsoSessionExpiredError.buildMessage(profileName));
 611    this.name = 'SsoSessionExpiredError';
 612    this.profileName = profileName;
 613    this.cause = cause;
 14  }
 15
 16  private static buildMessage(profileName?: string): string {
 617    if (profileName) {
 418      return (
 19        `Your AWS SSO session for profile '${profileName}' could not be ` +
 20        `loaded or has expired. Run: aws sso login --profile ${profileName} ` +
 21        'and then re-run this command.'
 22      );
 23    }
 224    return (
 25      'Your AWS SSO session could not be loaded or has expired. Run: ' +
 26      'aws sso login and then re-run this command.'
 27    );
 28  }
 29}
 30
 531const SSO_SESSION_EXPIRED_ERROR_NAMES = new Set(['TokenProviderError']);
 32
 33/**
 34 * Detects whether an unknown error represents an expired or unresolved AWS SSO
 35 * session, by inspecting its AWS error name.
 36 */
 37export function isSsoSessionExpiredError(error: unknown): boolean {
 838  if (typeof error !== 'object' || error === null || !('name' in error)) {
 139    return false;
 40  }
 741  const name = String((error as { name?: unknown }).name);
 742  return SSO_SESSION_EXPIRED_ERROR_NAMES.has(name);
 43}