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

@@ -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);