Преглед изворни кода

Adds better error handling for validation

main
Eric Amodio пре 3 година
родитељ
комит
ef55c8d728
2 измењених фајлова са 48 додато и 8 уклоњено
  1. +16
    -0
      src/errors.ts
  2. +32
    -8
      src/premium/subscription/subscriptionService.ts

+ 16
- 0
src/errors.ts Прегледај датотеку

@ -23,6 +23,22 @@ export class AccessDeniedError extends Error {
}
}
export class AccountValidationError extends Error {
readonly original?: Error;
readonly statusCode?: number;
readonly statusText?: string;
constructor(message: string, original?: Error, statusCode?: number, statusText?: string) {
message += `; status=${statusCode}: ${statusText}`;
super(message);
this.original = original;
this.statusCode = statusCode;
this.statusText = statusText;
Error.captureStackTrace?.(this, AccountValidationError);
}
}
export const enum AuthenticationErrorReason {
UserDidNotConsent = 1,
Unauthorized = 2,

+ 32
- 8
src/premium/subscription/subscriptionService.ts Прегледај датотеку

@ -18,6 +18,7 @@ import { getPlatform } from '@env/platform';
import { Commands, ContextKeys } from '../../constants';
import type { Container } from '../../container';
import { setContext } from '../../context';
import { AccountValidationError } from '../../errors';
import { RepositoriesChangeEvent } from '../../git/gitProviderService';
import { Logger } from '../../logger';
import { StorageKeys, WorkspaceStorageKeys } from '../../storage';
@ -339,10 +340,17 @@ export class SubscriptionService implements Disposable {
@gate()
@log()
async validate(): Promise<void> {
const cc = Logger.getCorrelationContext();
const session = await this.ensureSession(false);
if (session == null) return;
await this.checkInAndValidate(session);
try {
await this.checkInAndValidate(session);
} catch (ex) {
Logger.error(ex, cc);
debugger;
}
}
private async checkInAndValidate(session: AuthenticationSession): Promise<void> {
@ -368,10 +376,7 @@ export class SubscriptionService implements Disposable {
});
if (!rsp.ok) {
// TODO@eamodio clear the details if there is an error?
debugger;
this.logout();
return;
throw new AccountValidationError('Unable to validate account', undefined, rsp.status, rsp.statusText);
}
const data: GKLicenseInfo = await rsp.json();
@ -379,8 +384,9 @@ export class SubscriptionService implements Disposable {
} catch (ex) {
Logger.error(ex);
debugger;
// TODO@eamodio clear the details if there is an error?
this.logout();
if (ex instanceof AccountValidationError) throw ex;
throw new AccountValidationError('Unable to validate account', ex);
}
}
@ -506,7 +512,25 @@ export class SubscriptionService implements Disposable {
return session ?? null;
}
await this.checkInAndValidate(session);
try {
await this.checkInAndValidate(session);
} catch (ex) {
Logger.error(ex);
debugger;
const name = session.account.label;
session = null;
if (ex instanceof AccountValidationError) {
this.logout();
if (createIfNeeded) {
void window.showErrorMessage(
`Unable to sign in to your account. Please try again. If this issue persists, please contact support. Account=${name} Error=${ex.message}`,
'OK',
);
}
}
}
return session;
}

||||||
x
 
000:0
Loading…
Откажи
Сачувај