Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chamodshehanka committed Feb 28, 2022
1 parent c365ac3 commit 9003e75
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions github.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ class GitHubService {
throw new Error(`Head branch ${headBranch} does not exist in ${this.org}/${this.repo}`);
}
console.log(`Creating branch ${branch} with sha ${sha}`);
const response = await this.octokit.request('POST /repos/{owner}/{repo}/git/refs', {
owner: this.org,
repo: this.repo,
ref: `refs/heads/${branch}`,
sha: sha
});

return response.status === 201;
try {
const response = await this.octokit.request('POST /repos/{owner}/{repo}/git/refs', {
owner: this.org,
repo: this.repo,
ref: `refs/heads/${branch}`,
sha: sha
});

return response.status === 201;
} catch (e) {
console.log(`Branch ${branch} creation failed in ${this.org}/${this.repo}: [ERROR] ${e.message}`);
throw e;
}

}
}

Expand Down

0 comments on commit 9003e75

Please sign in to comment.