Bläddra i källkod

Fixes rogue "Authentication Required" notification

Happens when you are signed out and open the drafts view
main
Eric Amodio 1 år sedan
förälder
incheckning
f42d2caaf3
4 ändrade filer med 23 tillägg och 6 borttagningar
  1. +8
    -0
      src/errors.ts
  2. +2
    -1
      src/plus/focus/focusService.ts
  3. +2
    -1
      src/plus/gk/serverConnection.ts
  4. +11
    -4
      src/views/draftsView.ts

+ 8
- 0
src/errors.ts Visa fil

@ -86,6 +86,14 @@ export class AuthenticationError extends Error {
}
}
export class AuthenticationRequiredError extends Error {
constructor() {
super('Authentication required');
Error.captureStackTrace?.(this, AuthenticationRequiredError);
}
}
export class CancellationError extends _CancellationError {
constructor() {
super();

+ 2
- 1
src/plus/focus/focusService.ts Visa fil

@ -1,5 +1,6 @@
import type { Disposable } from 'vscode';
import type { Container } from '../../container';
import { AuthenticationRequiredError } from '../../errors';
import type { GitRemote } from '../../git/models/remote';
import type { RemoteProvider } from '../../git/remotes/remoteProvider';
import { log } from '../../system/decorators/log';
@ -84,7 +85,7 @@ export class FocusService implements Disposable {
const result = (await rsp.json()) as Result;
return type == null ? result.data : result.data.filter(i => i.type === type);
} catch (ex) {
if (ex instanceof Error && ex.message === 'Authentication required') return [];
if (ex instanceof AuthenticationRequiredError) return [];
Logger.error(ex, scope);
debugger;

+ 2
- 1
src/plus/gk/serverConnection.ts Visa fil

@ -3,6 +3,7 @@ import { Uri } from 'vscode';
import type { RequestInfo, RequestInit, Response } from '@env/fetch';
import { fetch as _fetch, getProxyAgent } from '@env/fetch';
import type { Container } from '../../container';
import { AuthenticationRequiredError } from '../../errors';
import { memoize } from '../../system/decorators/memoize';
import { Logger } from '../../system/logger';
import { getLogScope } from '../../system/logger.scope';
@ -159,7 +160,7 @@ export class ServerConnection implements Disposable {
const session = await this.container.subscription.getAuthenticationSession();
if (session != null) return session.accessToken;
throw new Error('Authentication required');
throw new AuthenticationRequiredError();
}
}

+ 11
- 4
src/views/draftsView.ts Visa fil

@ -3,6 +3,7 @@ import { TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import type { RepositoriesViewConfig } from '../config';
import { Commands } from '../constants';
import type { Container } from '../container';
import { AuthenticationRequiredError } from '../errors';
import { unknownGitUri } from '../git/gitUri';
import type { Draft } from '../gk/models/drafts';
import { showPatchesView } from '../plus/drafts/actions';
@ -24,10 +25,16 @@ export class DraftsViewNode extends CacheableChildrenViewNode<'drafts', DraftsVi
if (this.children == null) {
const children: DraftNode[] = [];
const drafts = await this.view.container.drafts.getDrafts();
drafts.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
for (const draft of drafts) {
children.push(new DraftNode(this.uri, this.view, this, draft));
try {
const drafts = await this.view.container.drafts.getDrafts();
drafts.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
for (const draft of drafts) {
children.push(new DraftNode(this.uri, this.view, this, draft));
}
} catch (ex) {
if (!(ex instanceof AuthenticationRequiredError)) {
throw ex;
}
}
this.children = children;

Laddar…
Avbryt
Spara