Skip to content
\n

The script being called

\n
module.exports = async ({ context, github, name, value }) => {\n  const { status } = await github.request('GET /repos/{owner}/{repo}/actions/variables/{name}', {\n    owner: context.repo.owner,\n    repo: context.repo.repo,\n    name: 'DOES_NOT_EXIST'\n  })\n  \n  console.log(status)\n}\n
\n
\n

The output logs when the step fails.

\n
RequestError [HttpError]: Not Found\nError: Unhandled error: HttpError: Not Found\n    at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:6842:21\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async module.exports (my stuff)\n    at async eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15143:16), <anonymous>:4:1)\n    at async main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15236:20) {\n  status: 404,\n  response: {\n    url: 'my-repo-url',\n    status: 404,\n    headers: {\n      'a-bunch-of-headers'\n    },\n    data: {\n      message: 'Not Found',\n      documentation_url: 'https://docs.github.com/rest/actions/variables#get-a-repository-variable'\n    }\n  },\n  request: {\n    method: 'GET',\n    url: 'my-url',\n    headers: {\n      accept: 'application/vnd.github.v3+json',\n      'user-agent': 'actions/github-script octokit-core.js/3.6.0 Node.js/16.16.0 (linux; x64)',\n      authorization: 'token [REDACTED]'\n    },\n    request: { agent: [Agent], hook: [Function: bound bound register] }\n  }\n}\n
","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"

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?

\n
const response = await github.request('GET /repos/{owner}/{repo}/actions/variables/{name}', {\n    owner: context.repo.owner,\n    repo: context.repo.repo,\n    name\n  }).catch(response => response)\n
","upvoteCount":1,"url":"https://github.com/actions/github-script/discussions/386#discussioncomment-5931227"}}}
Discussion options

You must be logged in to vote

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?

const response = await github.request('GET /repos/{owner}/{repo}/actions/variables/{name}', {
    owner: context.repo.owner,
    repo: context.repo.repo,
    name
  }).catch(response => response)

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by joshft91
Comment options

You must be logged in to vote
1 reply
@joshft91
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants