Skip to content

Commit 4a6cd8e

Browse files
committed
refactor: list of git auth error messages
1 parent 7b9f468 commit 4a6cd8e

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/git.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ export interface IGitPushPullResult {
192192
message?: string;
193193
}
194194

195+
/**
196+
* Array of Git Auth Error Messages
197+
*/
198+
export const AUTH_ERROR_MESSAGES = [
199+
'Invalid username or password',
200+
'could not read Username',
201+
'could not read Password'
202+
];
203+
195204
/** Parent class for all API requests */
196205
export class Git {
197206
constructor() {}

src/widgets/gitClone.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FileBrowser, IFileBrowserFactory } from '@jupyterlab/filebrowser';
66

77
import { style } from 'typestyle';
88

9-
import { Git } from '../git';
9+
import { Git, AUTH_ERROR_MESSAGES } from '../git';
1010

1111
import { GitCredentialsForm } from './CredentialsBox';
1212

@@ -91,8 +91,9 @@ export class GitClone extends Widget {
9191
while (response.code !== 0) {
9292
if (
9393
response.code === 128 &&
94-
(response.message.indexOf('could not read Username') >= 0 ||
95-
response.message.indexOf('Invalid username or password') >= 0)
94+
AUTH_ERROR_MESSAGES.map(
95+
message => response.message.indexOf(message) > -1
96+
).indexOf(true) > -1
9697
) {
9798
// request user credentials and try to clone again
9899
const dialog = new Dialog({

src/widgets/gitPushPull.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Spinner } from '@jupyterlab/apputils';
22
import { Widget } from '@phosphor/widgets';
3-
import { Git, IGitPushPullResult, IGitAuth } from '../git';
3+
import { Git, IGitPushPullResult, IGitAuth, AUTH_ERROR_MESSAGES } from '../git';
44

55
export enum Operation {
66
Pull = 'Pull',
@@ -75,8 +75,9 @@ export class GitPullPushDialog extends Widget {
7575
this.spinner.dispose();
7676
if (response.code !== 0) {
7777
if (
78-
response.message.indexOf('could not read Username') >= 0 ||
79-
response.message.indexOf('Invalid username or password') >= 0
78+
AUTH_ERROR_MESSAGES.map(
79+
message => response.message.indexOf(message) > -1
80+
).indexOf(true) > -1
8081
) {
8182
this.handleError(response.message);
8283
this.parent!.parent!.close();

0 commit comments

Comments
 (0)