diff --git a/public/script/app.js b/public/script/app.js index fddee23..1cc1c0d 100644 --- a/public/script/app.js +++ b/public/script/app.js @@ -1115,7 +1115,7 @@ angular if (data.terms) { $scope.terms = data.terms.join("\n"); } - $scope.option = Object.assign({}, $scope.option, data.options); + $scope.options = Object.assign({}, $scope.options, data.options); }); } getDefault(); diff --git a/src/core/source/GitHubRepository.ts b/src/core/source/GitHubRepository.ts index 439a880..3f8c463 100644 --- a/src/core/source/GitHubRepository.ts +++ b/src/core/source/GitHubRepository.ts @@ -4,7 +4,7 @@ import { RestEndpointMethodTypes } from "@octokit/rest"; import AnonymousError from "../AnonymousError"; import { isConnected } from "../../server/database"; -import { octokit } from "../GitHubUtils"; +import { checkToken, octokit } from "../GitHubUtils"; import { IRepositoryDocument } from "../model/repositories/repositories.types"; import RepositoryModel from "../model/repositories/repositories.model"; @@ -306,13 +306,36 @@ export async function getRepositoryFromGitHub(opt: { }) ).data as RestEndpointMethodTypes["repos"]["get"]["response"]["data"]; } catch (idError) { + const idStatus = (idError as { status?: number }).status; + if ( + idStatus === 401 || + idStatus === 403 || + !(await checkToken(opt.accessToken)) + ) { + throw new AnonymousError("token_expired", { + httpStatus: 401, + object: { owner: opt.owner, repo: opt.repo }, + cause: idError as Error, + }); + } throw new AnonymousError("repo_not_found", { - httpStatus: (idError as { status?: number }).status || 404, + httpStatus: idStatus || 404, object: { owner: opt.owner, repo: opt.repo }, cause: idError as Error, }); } } else { + if ( + status === 401 || + status === 403 || + !(await checkToken(opt.accessToken)) + ) { + throw new AnonymousError("token_expired", { + httpStatus: 401, + object: { owner: opt.owner, repo: opt.repo }, + cause: error as Error, + }); + } throw new AnonymousError("repo_not_found", { httpStatus: status, object: { diff --git a/src/core/zipStream.ts b/src/core/zipStream.ts index 6ab0f86..e651d91 100644 --- a/src/core/zipStream.ts +++ b/src/core/zipStream.ts @@ -3,6 +3,8 @@ import { Parse } from "unzip-stream"; import archiver = require("archiver"); import GitHubDownload from "./source/GitHubDownload"; +import { classifyGitHubMissError } from "./source/GitHubBase"; +import AnonymousError from "./AnonymousError"; import { AnonymizeTransformer, anonymizePathCompiled, @@ -81,7 +83,27 @@ export async function streamAnonymizedZip( getToken: opt.getToken, }); - const response = await source.getZipUrl(); + let response; + try { + response = await source.getZipUrl(); + } catch (error) { + const code = await classifyGitHubMissError(error, { + organization: opt.organization, + repoName: opt.repoName, + repoId: opt.repoId, + commit: opt.commit, + getToken: opt.getToken, + }); + const status = (error as { status?: number }).status; + throw new AnonymousError(code, { + httpStatus: status && status >= 500 ? 502 : status || 502, + cause: error as Error, + object: { + repoId: opt.repoId, + fullName: `${opt.organization}/${opt.repoName}`, + }, + }); + } const downloadStream = got.stream(response.url); res.on("error", (error) => {