fix: Branch used does not throw error
This commit is contained in:
		| @@ -74,13 +74,18 @@ | |||||||
| 	} | 	} | ||||||
| 	async function isBranchAlreadyUsed() { | 	async function isBranchAlreadyUsed() { | ||||||
| 		try { | 		try { | ||||||
| 			return await get( | 			const data = await get( | ||||||
| 				`/applications/${id}/configuration/repository.json?repository=${selected.repository}&branch=${selected.branch}` | 				`/applications/${id}/configuration/repository.json?repository=${selected.repository}&branch=${selected.branch}` | ||||||
| 			); | 			); | ||||||
| 		} catch ({ error }) { | 			if (data.used) { | ||||||
| 			return errorNotification(error); | 				errorNotification('This branch is already used by another application.'); | ||||||
| 		} finally { | 				showSave = false; | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
| 			showSave = true; | 			showSave = true; | ||||||
|  | 		} catch ({ error }) { | ||||||
|  | 			showSave = false; | ||||||
|  | 			return errorNotification(error); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -132,14 +132,18 @@ | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	async function isBranchAlreadyUsed() { | 	async function isBranchAlreadyUsed() { | ||||||
| 		const url = `/applications/${id}/configuration/repository.json?repository=${selected.project.path_with_namespace}&branch=${selected.branch.name}`; |  | ||||||
|  |  | ||||||
| 		try { | 		try { | ||||||
| 			await get(url); | 			const data = await get( | ||||||
|  | 				`/applications/${id}/configuration/repository.json?repository=${selected.project.path_with_namespace}&branch=${selected.branch.name}` | ||||||
|  | 			); | ||||||
|  | 			if (data.used) { | ||||||
|  | 				errorNotification('This branch is already used by another application.'); | ||||||
|  | 				showSave = false; | ||||||
|  | 				return true; | ||||||
|  | 			} | ||||||
| 			showSave = true; | 			showSave = true; | ||||||
| 		} catch (error) { | 		} catch ({ error }) { | ||||||
| 			showSave = false; | 			return errorNotification(error); | ||||||
| 			return errorNotification('Branch already configured'); |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	async function checkSSHKey(sshkeyUrl) { | 	async function checkSSHKey(sshkeyUrl) { | ||||||
| @@ -195,7 +199,6 @@ | |||||||
| 			const deployKeyFound = deployKeys.filter((dk) => dk.title === `${appId}-coolify-deploy-key`); | 			const deployKeyFound = deployKeys.filter((dk) => dk.title === `${appId}-coolify-deploy-key`); | ||||||
| 			if (deployKeyFound.length > 0) { | 			if (deployKeyFound.length > 0) { | ||||||
| 				for (const deployKey of deployKeyFound) { | 				for (const deployKey of deployKeyFound) { | ||||||
| 					console.log(`${deployKeyUrl}/${deployKey.id}`); |  | ||||||
| 					await del( | 					await del( | ||||||
| 						`${deployKeyUrl}/${deployKey.id}`, | 						`${deployKeyUrl}/${deployKey.id}`, | ||||||
| 						{}, | 						{}, | ||||||
|   | |||||||
| @@ -14,13 +14,11 @@ export const get: RequestHandler = async (event) => { | |||||||
|  |  | ||||||
| 	try { | 	try { | ||||||
| 		const found = await db.isBranchAlreadyUsed({ repository, branch, id }); | 		const found = await db.isBranchAlreadyUsed({ repository, branch, id }); | ||||||
| 		if (found) { |  | ||||||
| 			throw { |  | ||||||
| 				error: `Branch ${branch} is already used by another application` |  | ||||||
| 			}; |  | ||||||
| 		} |  | ||||||
| 		return { | 		return { | ||||||
| 			status: 200 | 			status: 200, | ||||||
|  | 			body: { | ||||||
|  | 				used: found ? true : false | ||||||
|  | 			} | ||||||
| 		}; | 		}; | ||||||
| 	} catch (error) { | 	} catch (error) { | ||||||
| 		return ErrorHandler(error); | 		return ErrorHandler(error); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andras Bacsai
					Andras Bacsai