-
Hello! 👋 I wasn't sure the best phrase to word the question, but hopefully this makes sense. I'm attempting to write a quick little function using Unfortunately, it doesn't look like I'd like to check for the existence of a repository variable prior to creating/updating that variable. I would expect a 404 response. However, when running the examples below I get a Step calling the script
The script being called
The output logs when the step fails.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I was messing around with this more and found this as a potential workaround/solution by catching thrown error and returning the response object. Is there a better/cleaner way?
|
Beta Was this translation helpful? Give feedback.
-
👋 Hey @joshft91, I think your solution is on the right track, you want to catch any errors being thrown by Octokit for errors. Here's another example in case you wanted to add some logic in the case of errors: module.exports = async ({ context, github, name, value }) => {
let status;
try {
const { respStatus } = await github.request('GET /repos/{owner}/{repo}/actions/variables/{name}', {
owner: context.repo.owner,
repo: context.repo.repo,
name: 'DOES_NOT_EXIST'
})
status = respStatus
} catch (e) {
status = e.status
}
console.log(status)
} |
Beta Was this translation helpful? Give feedback.
I was messing around with this more and found this as a potential workaround/solution by catching thrown error and returning the response object. Is there a better/cleaner way?