diff --git a/README.md b/README.md index 2fe5e3c..0495974 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,14 @@ jobs: method: 'POST' username: ${{ secrets.AWX_USER }} password: ${{ secrets.AWX_PASSWORD }} + customHeaders: '{"Content-Type": "application/json"}' + data: '{"key_1": "value_1", "key_2": "value_2"}' ``` +### Versioning + +`master` branch is deprecated. Please use `main` or `v1` to get the latest version of this action. It is recommended to use a fixed version. + ### Request Configuration |Argument| Description | Default | @@ -42,7 +48,7 @@ jobs: |---|---| `response` | Response as JSON String -To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs` +To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs`. You can also access specific field from the response data using [fromJson()](https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson) expression. ```yaml steps: @@ -52,7 +58,9 @@ steps: with: url: "http://yoursite.com/api" - name: Show Response - run: echo ${{ steps.myRequest.outputs.response }} + run: | + echo ${{ steps.myRequest.outputs.response }} + echo ${{ fromJson(steps.myRequest.outputs.response).field_you_want_to_access }} ``` ### Additional Information diff --git a/dist/index.js b/dist/index.js index 974d4e3..85dda49 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1969,8 +1969,9 @@ const request = async({ method, instanceConfig, data, files, file, auth, actions actions.setOutput('response', JSON.stringify(response.data)) } catch (error) { - if (error.toJSON) { - actions.setOutput('requestError', JSON.stringify(error.toJSON())); + if ((typeof error === 'object') && (error.isAxiosError === true)) { + const { name, message, code, response } = error + actions.setOutput('requestError', JSON.stringify({ name, message, code, status: response && response.status ? response.status : null })); } if (error.response && ignoredCodes.includes(error.response.status)) { diff --git a/src/httpClient.js b/src/httpClient.js index c167ab6..6cef368 100644 --- a/src/httpClient.js +++ b/src/httpClient.js @@ -71,8 +71,9 @@ const request = async({ method, instanceConfig, data, files, file, auth, actions actions.setOutput('response', JSON.stringify(response.data)) } catch (error) { - if (error.toJSON) { - actions.setOutput('requestError', JSON.stringify(error.toJSON())); + if ((typeof error === 'object') && (error.isAxiosError === true)) { + const { name, message, code, response } = error + actions.setOutput('requestError', JSON.stringify({ name, message, code, status: response && response.status ? response.status : null })); } if (error.response && ignoredCodes.includes(error.response.status)) {