improve error message

This commit is contained in:
tdurieux
2021-04-27 08:01:02 +02:00
parent b6c4b780b8
commit dc84de9d84
4 changed files with 66 additions and 30 deletions
+13 -2
View File
@@ -1,6 +1,8 @@
<div class="container-fluid h-100"> <div class="container-fluid h-100">
<div class="row 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 <div
class="p-0 py-2 m-auto" class="p-0 py-2 m-auto"
ng-class="{'card': !repoUrl,'container': repoUrl}" ng-class="{'card': !repoUrl,'container': repoUrl}"
@@ -35,6 +37,13 @@
Please provide a valid Github url, e.g., Please provide a valid Github url, e.g.,
https://github.com/owner/repo. https://github.com/owner/repo.
</div> </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 <div
class="invalid-feedback" class="invalid-feedback"
ng-show="anonymize.repoUrl.$error.missing" ng-show="anonymize.repoUrl.$error.missing"
@@ -177,7 +186,9 @@
</div> </div>
<!-- Conference --> <!-- Conference -->
<div class="form-group"> <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 <input
class="form-control" class="form-control"
id="conference" id="conference"
+43 -20
View File
@@ -232,9 +232,13 @@ angular
if (!$scope.file) return; if (!$scope.file) return;
$http.get($scope.file).then((res) => { $http.get($scope.file).then((res) => {
var notebook = nb.parse(res.data); var notebook = nb.parse(res.data);
var rendered = notebook.render(); try {
$element.append(rendered); var rendered = notebook.render();
Prism.highlightAll(); $element.append(rendered);
Prism.highlightAll();
} catch (error) {
$element.html("Unable to render the notebook.")
}
}); });
} }
$scope.$watch("file", (v) => { $scope.$watch("file", (v) => {
@@ -306,7 +310,7 @@ angular
$scope.$broadcast("dark-mode", on); $scope.$broadcast("dark-mode", on);
}; };
$scope.darkMode(localStorage.getItem("darkMode") == "true") $scope.darkMode(localStorage.getItem("darkMode") == "true");
function getUser() { function getUser() {
$http.get("/api/user").then( $http.get("/api/user").then(
@@ -570,7 +574,7 @@ angular
} }
}, },
(err) => { (err) => {
$scope.error = err.data; $scope.error = err.data.error;
} }
); );
}; };
@@ -771,7 +775,7 @@ angular
async function getDetails() { async function getDetails() {
const o = parseGithubUrl($scope.repoUrl); const o = parseGithubUrl($scope.repoUrl);
try { try {
$scope.anonymize.repoUrl.$setValidity("missing", true); resetValidity();
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`); const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`);
$scope.details = res.data; $scope.details = res.data;
if ($scope.details.size > 1024 * 8) { if ($scope.details.size > 1024 * 8) {
@@ -783,7 +787,12 @@ angular
$scope.repoId = $scope.details.name + "-" + generateRandomId(4); $scope.repoId = $scope.details.name + "-" + generateRandomId(4);
await $scope.getBranches(); await $scope.getBranches();
} catch (error) { } 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); $scope.anonymize.repoUrl.$setValidity("missing", false);
throw error; throw error;
} }
@@ -848,22 +857,12 @@ angular
$scope.anonymize.repoId.$setValidity("used", true); $scope.anonymize.repoId.$setValidity("used", true);
$scope.anonymize.repoId.$setValidity("format", true); $scope.anonymize.repoId.$setValidity("format", true);
$scope.anonymize.repoUrl.$setValidity("used", 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); $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) { function displayErrorMessage(message) {
switch (message) { switch (message) {
case "repoId_already_used": case "repoId_already_used":
@@ -881,11 +880,35 @@ angular
case "invalid_terms_format": case "invalid_terms_format":
$scope.anonymize.terms.$setValidity("format", false); $scope.anonymize.terms.$setValidity("format", false);
break; 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: default:
$scope.anonymize.$setValidity("error", false); $scope.anonymize.$setValidity("error", false);
break; 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) => { $scope.anonymizeRepo = async (event) => {
event.target.disabled = true; event.target.disabled = true;
resetValidity(); resetValidity();
+8 -8
View File
@@ -60,10 +60,10 @@ router.get("/:repoId/", async (req, res) => {
if (repository) { if (repository) {
return res.json(repository); return res.json(repository);
} }
res.status(404).send("repo_not_found"); res.status(404).send({error: "repo_not_found"});
} catch (error) { } catch (error) {
console.error(req.path, 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) { if (repository) {
return res.json(repository); return res.json(repository);
} }
res.status(404).send("repo_not_found"); res.status(404).send({error: "repo_not_found"});
} catch (error) { } catch (error) {
console.error(req.path, 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) { if (repository) {
return res.json(repository); return res.json(repository);
} }
res.status(404).send("repo_not_found"); res.status(404).send({error: "repo_not_found"});
} catch (error) { } catch (error) {
console.error(req.path, 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) { if (readme) {
return res.send(readme); return res.send(readme);
} }
res.status(404).send("repo_not_found"); res.status(404).send({error: "repo_not_found"});
} catch (error) { } catch (error) {
res.status(500).send(error); res.status(500).json({ error });
} }
}); });
+2
View File
@@ -102,6 +102,8 @@ module.exports.getRepoDetails = async (options) => {
if (error.status == 401 && options.token != config.GITHUB_TOKEN) { if (error.status == 401 && options.token != config.GITHUB_TOKEN) {
options.token = config.GITHUB_TOKEN; options.token = config.GITHUB_TOKEN;
return await module.exports.getRepoDetails(options); return await module.exports.getRepoDetails(options);
} else if (error.status == 403) {
throw "repo_not_accessible";
} }
throw "repo_not_found"; throw "repo_not_found";
} }