Display error messages

This commit is contained in:
tdurieux
2021-03-19 13:26:29 +01:00
parent 54bc4e176d
commit 72715dfcd9
17 changed files with 117 additions and 33 deletions

View File

@@ -21,6 +21,8 @@
<!-- JS -->
<script src="/script/external/angular.min.js"></script>
<script src="/script/external/angular-translate.min.js"></script>
<script src="/script/external/angular-translate-loader-static-files.min.js"></script>
<script src="/script/external/angular-sanitize.min.js"></script>
<script src="/script/external/angular-route.min.js"></script>

View File

@@ -0,0 +1,31 @@
{
"ERRORS": {
"repo_not_found": "The repository is not found.",
"repo_not_accessible": "Anonymous GitHub does not have the persmission to access the repository.",
"repository_expired": "The repository is expired",
"repository_not_ready": "Anonymous GitHub is still processing the repository, it can take several minutes.",
"repo_is_updating": "Anonymous GitHub is still processing the repository, it can take several minutes.",
"repoUrl_not_defined": "The repository url needs to be defined.",
"repoId_already_used": "The repository id is already used.",
"invalid_repoId": "The format of the repository id is invalid",
"branch_not_specified": "The branch is not specified",
"options_not_provided": "options_not_provided",
"invalid_terms_format": "invalid_terms_format",
"unable_to_anonymize": "unable_to_anonymize",
"non_supported_mode": "The selected anonymization mode is invalid, only download and stream are supported.",
"invalid_path": "The provided path is invalid or missing.",
"file_not_found": "The requested file is not found.",
"file_not_accessible": "The requested file is not accessible.",
"file_not_supported": "The file type is not supported. Anonymous GitHub cannot handle it.",
"file_too_big": "The file size exceed the limit of Anonymous GitHub.",
"is_folder": "The path points to a folder.",
"unable_to_write_file": "Unable to write file on disk.",
"stats_unsupported": "Statistics are only supported in download mode.",
"branches_not_found": "The requested branch is not found.",
"readme_not_available": "No readme for the repository is found.",
"user_not_found": "The current user is not found in the database",
"not_connected": "User is not connectd",
"page_not_supported_on_different_branch": "Anonimized GitHub pages are only supported on the same branch.",
"page_not_activated": "Anonimized GitHub page is not enabled."
}
}

View File

@@ -17,6 +17,8 @@
<!-- JS -->
<script src="/script/external/angular.min.js"></script>
<script src="/script/external/angular-sanitize.min.js"></script>
<script src="/script/external/angular-translate.min.js"></script>
<script src="/script/external/angular-translate-loader-static-files.min.js"></script>
<script src="/script/external/angular-route.min.js"></script>
<script src="/script/external/jquery-3.4.1.min.js"></script>

View File

@@ -1,6 +1,5 @@
<div class="container-fluid main">
<ng-include src="'partials/header.htm'"></ng-include>
<div class="row center">
<div class="container text-center"><h1 class="display-1">404</h1></div>
</div>
<div class="container d-flex h-100">
<h1 class=" m-auto text-center">
<div class="display-1">404</div><small class="text-muted">Page not found</small>
</h1>
</div>

View File

@@ -459,7 +459,12 @@
</div>
</div>
</div>
<div
class="alert alert-danger"
role="alert"
ng-if="error"
ng-bind="error"
></div>
<button
id="submit"
type="submit"

View File

@@ -98,7 +98,7 @@
</thead>
<tbody>
<tr
ng-repeat="repo in repositories| filter:repoFiler| orderBy:orderBy"
ng-repeat="repo in repositories| filter:repoFiler| orderBy:orderBy as filteredRepositories"
>
<th scope="row">{{$index + 1}}</th>
<td>
@@ -178,6 +178,10 @@
</div>
</td>
</tr>
<tr ng-hide="filteredRepositories.length">
<td></td>
<td>No Repository</td>
</tr>
</tbody>
</table>
</div>

View File

@@ -6,5 +6,5 @@
<pdfviewer class="h-100 overflow-auto" src="{{url}}" id="viewer"></pdfviewer>
</div>
<div ng-if="type == 'IPython'"><notebook file="url"></notebook></div>
<div ng-if="type == 'error'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto" ng-bind="content">Error</h1></div></div>
<div ng-if="type == 'error'" class="file-error container d-flex h-100"><h1 class="display-1 m-auto" translate="ERRORS.{{content}}">Error</h1></div></div>
<div ng-if="content == null" class="file-error container d-flex h-100"><h1 class="display-1 m-auto">Empty file!</h1></div>

View File

@@ -1,4 +1,4 @@
<div class="container d-flex h-100">
<h1 class="display-1 m-auto" ng-if="!error">Loading...</h1>
<h1 class="display-1 m-auto" ng-if="error" ng-bind="error"></h1>
<h1 class="display-1 m-auto" ng-if="error" translate="{{error}}"></h1>
</div>

View File

@@ -4,8 +4,16 @@ angular
"ngSanitize",
"ui.ace",
"ngPDFViewer",
"pascalprecht.translate",
])
.config(function($routeProvider, $locationProvider) {
.config(function($routeProvider, $locationProvider, $translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: "/i18n/locale-",
suffix: ".json",
});
$translateProvider.preferredLanguage("en");
$routeProvider
.when("/:path*", {
templateUrl: "/partials/explore.htm",
@@ -311,13 +319,7 @@ angular
}
},
(err) => {
if (err.data.error == "repository_expired") {
$scope.error = "The repository is not available!";
} else if (err.data.error == "repo_not_found") {
$scope.error = "The repository is not found!";
} else {
console.log(err);
}
$scope.error = err.data.error;
}
);
}
@@ -451,8 +453,14 @@ angular
},
(err) => {
$scope.type = "error";
console.log(err);
$scope.content = err.data;
try {
err.data = JSON.parse(err.data);
} catch (ignore) {}
if (err.data.error) {
$scope.content = err.data.error;
} else {
$scope.content = err.data;
}
}
);
}

View File

@@ -0,0 +1,6 @@
/*!
* angular-translate - v2.18.4 - 2021-01-14
*
* Copyright (c) 2021 The angular-translate team, Pascal Precht; Licensed MIT
*/
!function(e,i){"function"==typeof define&&define.amd?define([],function(){return i()}):"object"==typeof module&&module.exports?module.exports=i():i()}(0,function(){function e(n,a){"use strict";return function(r){if(!(r&&(angular.isArray(r.files)||angular.isString(r.prefix)&&angular.isString(r.suffix))))throw new Error("Couldn't load static files, no files and prefix or suffix specified!");r.files||(r.files=[{prefix:r.prefix,suffix:r.suffix}]);for(var e=function(e){if(!e||!angular.isString(e.prefix)||!angular.isString(e.suffix))throw new Error("Couldn't load static file, no prefix or suffix specified!");var i=[e.prefix,r.key,e.suffix].join("");return angular.isObject(r.fileMap)&&r.fileMap[i]&&(i=r.fileMap[i]),a(angular.extend({url:i,method:"GET"},r.$http)).then(function(e){return e.data},function(){return n.reject(r.key)})},i=[],t=r.files.length,f=0;f<t;f++)i.push(e({prefix:r.files[f].prefix,key:r.key,suffix:r.files[f].suffix}));return n.all(i).then(function(e){for(var i=e.length,r={},t=0;t<i;t++)for(var f in e[t])r[f]=e[t][f];return r})}}return e.$inject=["$q","$http"],angular.module("pascalprecht.translate").factory("$translateStaticFilesLoader",e),e.displayName="$translateStaticFilesLoader","pascalprecht.translate"});

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,17 @@
angular
.module("anonymous-github", ["ngRoute", "ngSanitize"])
.config(function($routeProvider, $locationProvider) {
.module("anonymous-github", [
"ngRoute",
"ngSanitize",
"pascalprecht.translate",
])
.config(function($routeProvider, $locationProvider, $translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: "/i18n/locale-",
suffix: ".json",
});
$translateProvider.preferredLanguage("en");
$routeProvider
.when("/", {
templateUrl: "/partials/home.htm",
@@ -199,7 +210,8 @@ angular
$http,
$sce,
$routeParams,
$location
$location,
$translate
) {
$scope.repoUrl = "";
$scope.repoId = "";
@@ -233,8 +245,11 @@ angular
$scope.repoUrl = "https://github.com/" + res.data.fullName;
$scope.terms = res.data.terms.join("\n");
$scope.branch = res.data.branch;
$scope.options = res.data.options;
$scope.options.expirationDate = new Date(res.data.options.expirationDate);
$scope.options.expirationDate = new Date(
res.data.options.expirationDate
);
$scope.details = (await $http.get(
`/api/repo/${res.data.fullName}/`
@@ -301,7 +316,7 @@ angular
if ($scope.branches && $scope.branches[$scope.branch]) {
$scope.commit = $scope.branches[$scope.branch].commit.sha;
}
if ($scope.details.has_page) {
if ($scope.details && $scope.details.has_page) {
$scope.anonymize.page.disabled(false);
if ($scope.details.pageSource.branch != $scope.branch) {
$scope.anonymize.page.disabled(true);
@@ -334,7 +349,9 @@ angular
{ params: { force: force === true ? "1" : "0" } }
);
$scope.branches = branches.data;
$scope.branch = $scope.details.default_branch;
if (!$scope.branch) {
$scope.branch = $scope.details.default_branch;
}
if ($scope.branches[$scope.branch]) {
$scope.commit = $scope.branches[$scope.branch].commit.sha;
}
@@ -476,6 +493,9 @@ angular
window.location.href = "/r/" + $scope.repoId;
} catch (error) {
if (error.data) {
$translate("ERRORS." + error.data.error).then((translation) => {
$scope.error = translation;
}, console.error);
displayErrorMessage(error.data.error);
} else {
console.error(error);

View File

@@ -23,6 +23,7 @@ async function anonymizeRepository(options) {
console.log("The repository is expired");
await repoUtils.updateStatus(repoConfig, "expired");
await repoUtils.removeRepository(repoConfig);
throw "repository_expired";
return;
}
}
@@ -150,7 +151,7 @@ router.get("/:repoId/file/:path*", async (req, res) => {
);
return res.sendFile(ppath, { dotfiles: "allow" });
} else {
return res.status(404).send({ error: "file_not_found" });
return res.status(404).json({ error: "file_not_found" });
}
} catch (error) {
console.error(error);

View File

@@ -277,7 +277,7 @@ router.post("/", async (req, res) => {
if (repoConfig.options.mode == "download") {
// details.size is in kilobytes
if (details.size > config.MAX_REPO_SIZE) {
return res.status(500).send({ error: "invalid_mode" });
return res.status(500).send({ error: "non_supported_mode" });
}
}
@@ -326,7 +326,7 @@ router.post("/", async (req, res) => {
await repoUtils.updateStatus(repoConfig, "error");
return res
.status(500)
.json({ error: "unable_to_access", message: error.message });
.json({ error: "unable_to_anonymize", message: error.message });
}
res.send("ok");
});

View File

@@ -60,7 +60,7 @@ router.get("/all_repositories", async (req, res) => {
{ projection: { repositories: 1 } }
);
if (!user) {
res.status(401).send("User not found");
res.status(401).send({error: "user_not_found"});
}
if (user.repositories && req.query.force !== "1") {
return res.json(user.repositories);

View File

@@ -62,7 +62,7 @@ async function webView(req, res) {
console.error(error);
return res.status(500).send({ error });
}
return res.status(404).send("File_not_found");
return res.status(404).send("file_not_found");
}
router.get("/:repoId/*", webView);

View File

@@ -416,13 +416,13 @@ module.exports.isFilePathValid = async (options) => {
}
if (error.status == 403) {
console.log(error);
throw "content_too_large";
throw "file_too_big";
}
throw error;
}
}
if (!ghRes.data.content && ghRes.data.size != 0) {
throw "content_not_accessible";
throw "file_not_accessible";
}
// empty file
let content = "";
@@ -460,7 +460,7 @@ module.exports.getStats = async (options) => {
if (repoConfig == null) {
throw "repo_not_found";
}
if (repoConfig.mode == "stream") {
if (repoConfig.mode != "download") {
throw "stats_unsupported";
}