feat: improve error message during anonimization

This commit is contained in:
tdurieux
2023-02-07 09:03:04 +01:00
parent 8ea2a7f246
commit 6d4067bf6d
+38 -13
View File
@@ -1050,11 +1050,7 @@ angular
); );
} }
$scope.details = ( await getDetails();
await $http.get(`/api/repo/${res.data.source.fullName}/`)
).data;
await $scope.getBranches();
await getReadme(); await getReadme();
anonymize(); anonymize();
$scope.$apply(); $scope.$apply();
@@ -1157,6 +1153,7 @@ angular
if (selected.length > 0) { if (selected.length > 0) {
$scope.source.commit = selected[0].commit; $scope.source.commit = selected[0].commit;
$scope.readme = selected[0].readme; $scope.readme = selected[0].readme;
await getReadme(force);
} }
$scope.$apply(); $scope.$apply();
}; };
@@ -1178,11 +1175,25 @@ angular
$scope.repoId = $scope.details.repo + "-" + generateRandomId(4); $scope.repoId = $scope.details.repo + "-" + generateRandomId(4);
await $scope.getBranches(); await $scope.getBranches();
} catch (error) { } catch (error) {
console.log("here", error);
if (error.data) { if (error.data) {
$translate("ERRORS." + error.data.error).then((translation) => { $translate("ERRORS." + error.data.error).then((translation) => {
const toast = {
title: `Error when getting repository information`,
date: new Date(),
body: `${o.owner}/${o.repo} produice the following error: ${translation}`,
};
$scope.toasts.push(toast);
$scope.error = translation; $scope.error = translation;
}, console.error); }, console.error);
displayErrorMessage(error.data.error); displayErrorMessage(error.data.error);
} else {
const toast = {
title: `Error when getting repository information`,
date: new Date(),
body: `${o.owner}/${o.repo} produice the following error: ${error.message}`,
};
$scope.toasts.push(toast);
} }
$scope.anonymize.repoUrl.$setValidity("missing", false); $scope.anonymize.repoUrl.$setValidity("missing", false);
throw error; throw error;
@@ -1190,15 +1201,29 @@ angular
} }
async function getReadme(force) { async function getReadme(force) {
if ($scope.readme) return $scope.readme; if ($scope.readme && !force) return $scope.readme;
const o = parseGithubUrl($scope.repoUrl); const o = parseGithubUrl($scope.repoUrl);
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/readme`, { $http
params: { .get(`/api/repo/${o.owner}/${o.repo}/readme`, {
force: force === true ? "1" : "0", params: {
branch: $scope.source.branch, force: force === true ? "1" : "0",
}, branch: $scope.source.branch,
}); },
$scope.readme = res.data; })
.then(
(res) => {
$scope.readme = res.data;
},
() => {
$scope.readme = "";
const toast = {
title: `README not available...`,
date: new Date(),
body: `The README of ${o.owner}/${o.repo} was not found.`,
};
$scope.toasts.push(toast);
}
);
} }
function getConference() { function getConference() {