Skip to content

Commit 39fadd6

Browse files
committed
fix: auth issue & profile save issue
1 parent e73ad48 commit 39fadd6

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

public/script/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ angular
11151115
if (data.terms) {
11161116
$scope.terms = data.terms.join("\n");
11171117
}
1118-
$scope.option = Object.assign({}, $scope.option, data.options);
1118+
$scope.options = Object.assign({}, $scope.options, data.options);
11191119
});
11201120
}
11211121
getDefault();

src/core/source/GitHubRepository.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { RestEndpointMethodTypes } from "@octokit/rest";
44

55
import AnonymousError from "../AnonymousError";
66
import { isConnected } from "../../server/database";
7-
import { octokit } from "../GitHubUtils";
7+
import { checkToken, octokit } from "../GitHubUtils";
88
import { IRepositoryDocument } from "../model/repositories/repositories.types";
99
import RepositoryModel from "../model/repositories/repositories.model";
1010

@@ -306,13 +306,36 @@ export async function getRepositoryFromGitHub(opt: {
306306
})
307307
).data as RestEndpointMethodTypes["repos"]["get"]["response"]["data"];
308308
} catch (idError) {
309+
const idStatus = (idError as { status?: number }).status;
310+
if (
311+
idStatus === 401 ||
312+
idStatus === 403 ||
313+
!(await checkToken(opt.accessToken))
314+
) {
315+
throw new AnonymousError("token_expired", {
316+
httpStatus: 401,
317+
object: { owner: opt.owner, repo: opt.repo },
318+
cause: idError as Error,
319+
});
320+
}
309321
throw new AnonymousError("repo_not_found", {
310-
httpStatus: (idError as { status?: number }).status || 404,
322+
httpStatus: idStatus || 404,
311323
object: { owner: opt.owner, repo: opt.repo },
312324
cause: idError as Error,
313325
});
314326
}
315327
} else {
328+
if (
329+
status === 401 ||
330+
status === 403 ||
331+
!(await checkToken(opt.accessToken))
332+
) {
333+
throw new AnonymousError("token_expired", {
334+
httpStatus: 401,
335+
object: { owner: opt.owner, repo: opt.repo },
336+
cause: error as Error,
337+
});
338+
}
316339
throw new AnonymousError("repo_not_found", {
317340
httpStatus: status,
318341
object: {

src/core/zipStream.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Parse } from "unzip-stream";
33
import archiver = require("archiver");
44

55
import GitHubDownload from "./source/GitHubDownload";
6+
import { classifyGitHubMissError } from "./source/GitHubBase";
7+
import AnonymousError from "./AnonymousError";
68
import {
79
AnonymizeTransformer,
810
anonymizePathCompiled,
@@ -81,7 +83,27 @@ export async function streamAnonymizedZip(
8183
getToken: opt.getToken,
8284
});
8385

84-
const response = await source.getZipUrl();
86+
let response;
87+
try {
88+
response = await source.getZipUrl();
89+
} catch (error) {
90+
const code = await classifyGitHubMissError(error, {
91+
organization: opt.organization,
92+
repoName: opt.repoName,
93+
repoId: opt.repoId,
94+
commit: opt.commit,
95+
getToken: opt.getToken,
96+
});
97+
const status = (error as { status?: number }).status;
98+
throw new AnonymousError(code, {
99+
httpStatus: status && status >= 500 ? 502 : status || 502,
100+
cause: error as Error,
101+
object: {
102+
repoId: opt.repoId,
103+
fullName: `${opt.organization}/${opt.repoName}`,
104+
},
105+
});
106+
}
85107
const downloadStream = got.stream(response.url);
86108

87109
res.on("error", (error) => {

0 commit comments

Comments
 (0)