mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-02-13 10:52:53 +00:00
improve error message
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<div class="container-fluid h-100">
|
||||
<div class="row h-100">
|
||||
<div class="col sidePanel shadow overflow-auto h-100 d-flex align-content-end">
|
||||
<div
|
||||
class="col sidePanel shadow overflow-auto h-100 d-flex align-content-end"
|
||||
>
|
||||
<div
|
||||
class="p-0 py-2 m-auto"
|
||||
ng-class="{'card': !repoUrl,'container': repoUrl}"
|
||||
@@ -35,6 +37,13 @@
|
||||
Please provide a valid Github url, e.g.,
|
||||
https://github.com/owner/repo.
|
||||
</div>
|
||||
<div
|
||||
class="invalid-feedback"
|
||||
ng-show="anonymize.repoUrl.$error.access"
|
||||
>
|
||||
{{repoUrl}} is not accessible. Some organizations are restricting
|
||||
the access to the repositories.
|
||||
</div>
|
||||
<div
|
||||
class="invalid-feedback"
|
||||
ng-show="anonymize.repoUrl.$error.missing"
|
||||
@@ -177,7 +186,9 @@
|
||||
</div>
|
||||
<!-- Conference -->
|
||||
<div class="form-group">
|
||||
<label for="conference">Conference <span class="text-muted">Optional</span></label>
|
||||
<label for="conference"
|
||||
>Conference <span class="text-muted">Optional</span></label
|
||||
>
|
||||
<input
|
||||
class="form-control"
|
||||
id="conference"
|
||||
|
||||
@@ -232,9 +232,13 @@ angular
|
||||
if (!$scope.file) return;
|
||||
$http.get($scope.file).then((res) => {
|
||||
var notebook = nb.parse(res.data);
|
||||
var rendered = notebook.render();
|
||||
$element.append(rendered);
|
||||
Prism.highlightAll();
|
||||
try {
|
||||
var rendered = notebook.render();
|
||||
$element.append(rendered);
|
||||
Prism.highlightAll();
|
||||
} catch (error) {
|
||||
$element.html("Unable to render the notebook.")
|
||||
}
|
||||
});
|
||||
}
|
||||
$scope.$watch("file", (v) => {
|
||||
@@ -306,7 +310,7 @@ angular
|
||||
$scope.$broadcast("dark-mode", on);
|
||||
};
|
||||
|
||||
$scope.darkMode(localStorage.getItem("darkMode") == "true")
|
||||
$scope.darkMode(localStorage.getItem("darkMode") == "true");
|
||||
|
||||
function getUser() {
|
||||
$http.get("/api/user").then(
|
||||
@@ -570,7 +574,7 @@ angular
|
||||
}
|
||||
},
|
||||
(err) => {
|
||||
$scope.error = err.data;
|
||||
$scope.error = err.data.error;
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -771,7 +775,7 @@ angular
|
||||
async function getDetails() {
|
||||
const o = parseGithubUrl($scope.repoUrl);
|
||||
try {
|
||||
$scope.anonymize.repoUrl.$setValidity("missing", true);
|
||||
resetValidity();
|
||||
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`);
|
||||
$scope.details = res.data;
|
||||
if ($scope.details.size > 1024 * 8) {
|
||||
@@ -783,7 +787,12 @@ angular
|
||||
$scope.repoId = $scope.details.name + "-" + generateRandomId(4);
|
||||
await $scope.getBranches();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (error.data) {
|
||||
$translate("ERRORS." + error.data.error).then((translation) => {
|
||||
$scope.error = translation;
|
||||
}, console.error);
|
||||
displayErrorMessage(error.data.error);
|
||||
}
|
||||
$scope.anonymize.repoUrl.$setValidity("missing", false);
|
||||
throw error;
|
||||
}
|
||||
@@ -848,22 +857,12 @@ angular
|
||||
$scope.anonymize.repoId.$setValidity("used", true);
|
||||
$scope.anonymize.repoId.$setValidity("format", true);
|
||||
$scope.anonymize.repoUrl.$setValidity("used", true);
|
||||
$scope.anonymize.repoUrl.$setValidity("missing", true);
|
||||
$scope.anonymize.repoUrl.$setValidity("access", true);
|
||||
$scope.anonymize.terms.$setValidity("format", true);
|
||||
$scope.anonymize.terms.$setValidity("format", true);
|
||||
}
|
||||
|
||||
function getRepo() {
|
||||
const o = parseGithubUrl($scope.repoUrl);
|
||||
return {
|
||||
repoId: $scope.repoId,
|
||||
terms: $scope.terms.trim().split("\n"),
|
||||
fullName: `${o.owner}/${o.repo}`,
|
||||
repository: $scope.repoUrl,
|
||||
options: $scope.options,
|
||||
branch: $scope.branch,
|
||||
commit: $scope.commit,
|
||||
conference: $scope.conference,
|
||||
};
|
||||
}
|
||||
function displayErrorMessage(message) {
|
||||
switch (message) {
|
||||
case "repoId_already_used":
|
||||
@@ -881,11 +880,35 @@ angular
|
||||
case "invalid_terms_format":
|
||||
$scope.anonymize.terms.$setValidity("format", false);
|
||||
break;
|
||||
case "invalid_terms_format":
|
||||
$scope.anonymize.terms.$setValidity("format", false);
|
||||
break;
|
||||
case "repo_not_found":
|
||||
$scope.anonymize.repoUrl.$setValidity("missing", false);
|
||||
break;
|
||||
case "repo_not_accessible":
|
||||
$scope.anonymize.repoUrl.$setValidity("access", false);
|
||||
break;
|
||||
default:
|
||||
$scope.anonymize.$setValidity("error", false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function getRepo() {
|
||||
const o = parseGithubUrl($scope.repoUrl);
|
||||
return {
|
||||
repoId: $scope.repoId,
|
||||
terms: $scope.terms.trim().split("\n"),
|
||||
fullName: `${o.owner}/${o.repo}`,
|
||||
repository: $scope.repoUrl,
|
||||
options: $scope.options,
|
||||
branch: $scope.branch,
|
||||
commit: $scope.commit,
|
||||
conference: $scope.conference,
|
||||
};
|
||||
}
|
||||
|
||||
$scope.anonymizeRepo = async (event) => {
|
||||
event.target.disabled = true;
|
||||
resetValidity();
|
||||
|
||||
@@ -60,10 +60,10 @@ router.get("/:repoId/", async (req, res) => {
|
||||
if (repository) {
|
||||
return res.json(repository);
|
||||
}
|
||||
res.status(404).send("repo_not_found");
|
||||
res.status(404).send({error: "repo_not_found"});
|
||||
} catch (error) {
|
||||
console.error(req.path, error);
|
||||
res.status(500).send(error);
|
||||
res.status(500).json({ error });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -219,10 +219,10 @@ router.get("/:owner/:repo/", async (req, res) => {
|
||||
if (repository) {
|
||||
return res.json(repository);
|
||||
}
|
||||
res.status(404).send("repo_not_found");
|
||||
res.status(404).send({error: "repo_not_found"});
|
||||
} catch (error) {
|
||||
console.error(req.path, error);
|
||||
res.status(500).send(error);
|
||||
res.status(500).json({ error });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -237,10 +237,10 @@ router.get("/:owner/:repo/branches", async (req, res) => {
|
||||
if (repository) {
|
||||
return res.json(repository);
|
||||
}
|
||||
res.status(404).send("repo_not_found");
|
||||
res.status(404).send({error: "repo_not_found"});
|
||||
} catch (error) {
|
||||
console.error(req.path, error);
|
||||
res.status(500).send(error);
|
||||
res.status(500).json({ error });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -255,9 +255,9 @@ router.get("/:owner/:repo/readme", async (req, res) => {
|
||||
if (readme) {
|
||||
return res.send(readme);
|
||||
}
|
||||
res.status(404).send("repo_not_found");
|
||||
res.status(404).send({error: "repo_not_found"});
|
||||
} catch (error) {
|
||||
res.status(500).send(error);
|
||||
res.status(500).json({ error });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -102,6 +102,8 @@ module.exports.getRepoDetails = async (options) => {
|
||||
if (error.status == 401 && options.token != config.GITHUB_TOKEN) {
|
||||
options.token = config.GITHUB_TOKEN;
|
||||
return await module.exports.getRepoDetails(options);
|
||||
} else if (error.status == 403) {
|
||||
throw "repo_not_accessible";
|
||||
}
|
||||
throw "repo_not_found";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user