diff --git a/Containers/RepoManage/RepoManage.js b/Containers/RepoManage/RepoManage.js index 6045976..4d19db2 100644 --- a/Containers/RepoManage/RepoManage.js +++ b/Containers/RepoManage/RepoManage.js @@ -178,7 +178,7 @@ export default function RepoManage(props) { }, body: JSON.stringify(newRepo), }) - .then((response) => { + .then(async (response) => { if (response.ok) { toast.success( 'New repository added ! 🥳', @@ -186,9 +186,13 @@ export default function RepoManage(props) { ); router.replace('/'); } else { - toast.error('An error has occurred', toastOptions); + const errorMessage = await response.json(); + toast.error( + `An error has occurred : ${errorMessage.message}`, + toastOptions + ); router.replace('/'); - console.log('Fail to post'); + console.log(`Fail to ${props.mode}`); } }) .catch((error) => { @@ -213,7 +217,7 @@ export default function RepoManage(props) { }, body: JSON.stringify(dataEdited), }) - .then((response) => { + .then(async (response) => { if (response.ok) { toast.success( 'The repository #' + @@ -223,9 +227,13 @@ export default function RepoManage(props) { ); router.replace('/'); } else { - toast.error('An error has occurred', toastOptions); + const errorMessage = await response.json(); + toast.error( + `An error has occurred : ${errorMessage.message}`, + toastOptions + ); router.replace('/'); - console.log('Fail to PUT'); + console.log(`Fail to ${props.mode}`); } }) .catch((error) => { diff --git a/pages/api/repo/add.js b/pages/api/repo/add.js index 705ec40..9963a60 100644 --- a/pages/api/repo/add.js +++ b/pages/api/repo/add.js @@ -65,17 +65,10 @@ export default async function handler(req, res) { //Find the absolute path of the shells directory const shellsDirectory = path.join(process.cwd(), '/helpers'); //Exec the shell - const { stdout, stderr } = await exec( + const { stdout } = await exec( `${shellsDirectory}/shells/createRepo.sh "${newRepo.sshPublicKey}" ${newRepo.storageSize}` ); - if (stderr) { - console.log('stderr:', stderr); - res.status(500).json({ - status: 500, - message: 'Error on creation, contact the administrator.', - }); - return; - } + newRepo.repositoryName = stdout.trim(); //Create the new repoList with the new repo @@ -105,7 +98,7 @@ export default async function handler(req, res) { } else { res.status(500).json({ status: 500, - message: 'API error, contact the administrator', + message: error.stdout, }); } return; diff --git a/pages/api/repo/id/[slug]/edit.js b/pages/api/repo/id/[slug]/edit.js index 0cb1969..0476461 100644 --- a/pages/api/repo/id/[slug]/edit.js +++ b/pages/api/repo/id/[slug]/edit.js @@ -28,7 +28,6 @@ export default async function handler(req, res) { } try { - //console.log('API call (PUT)'); //Find the absolute path of the json directory const jsonDirectory = path.join(process.cwd(), '/config'); let repoList = await fs.readFile( @@ -48,17 +47,9 @@ export default async function handler(req, res) { //Find the absolute path of the shells directory const shellsDirectory = path.join(process.cwd(), '/helpers'); // //Exec the shell - const { stderr } = await exec( + await exec( `${shellsDirectory}/shells/updateRepo.sh ${repoList[repoIndex].repositoryName} "${sshPublicKey}" ${size}` ); - if (stderr) { - console.log('stderr:', stderr); - res.status(500).json({ - status: 500, - message: 'Error on update, contact the administrator.', - }); - return; - } //Find the ID in the data and change the values transmitted by the form let newRepoList = repoList.map((repo) => @@ -97,7 +88,7 @@ export default async function handler(req, res) { } else { res.status(500).json({ status: 500, - message: 'API error, contact the administrator', + message: error.stdout, }); } return;