Remove nested try-catch

Signed-off-by: Arthur Gavlyukovskiy <agavlyukovskiy@gmail.com>
This commit is contained in:
Arthur Gavlyukovskiy
2024-01-09 12:01:29 +01:00
parent 7c522c5ef8
commit 7a39edd3f9
@@ -149,22 +149,27 @@ export const createGitlabRepoPushAction = (options: {
execute_filemode: file.executable,
}));
let branchExists = false;
try {
await api.Branches.show(repoID, branchName);
} catch (e) {
branchExists = true;
} catch (e: any) {
if (e.response?.statusCode !== 404) {
throw new InputError(
`Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${e}`,
);
}
}
if (!branchExists) {
// create a branch using the default branch as ref
try {
const projects = await api.Projects.show(repoID);
const { default_branch: defaultBranch } = projects;
await api.Branches.create(repoID, branchName, String(defaultBranch));
} catch (e2) {
} catch (e) {
throw new InputError(
`The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${e2}`,
`The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${e}`,
);
}
}