Skip to content

Conversation

@DylanFM
Copy link

@DylanFM DylanFM commented Apr 26, 2022

When error responses are received from the Render API it doesn't fail the job. I noticed this when encountering a 401 error upon first getting this setup. So this uses Response.ok to check if the response is successful, otherwise fails the job.

Also, I have been wanting a bit more output showing what Render responds with when triggering a deploy. Not 100% sure what's best for the output here, but the this should be a bit more useful.

e.g

Run dylanfm/render-deploy-action@status-fails
Deploy build_in_progress - Commit: Revert "Reference with sha"

This reverts commit 56d02be7aece6e5d050c3240abeb0be0e41e79ea.

if (response.ok) {
core.info(`Deploy ${data.status} - Commit: ${data.commit.message}`)
} else {
core.setFailed(`Deploy error: ${data.message} (status code ${response.status})`)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing an issue here. It seems like it is an issue with the Render API not behaving like the documentation suggests.

Docs show that a 401 error should return the error object like other error responses

image

However, it seems that a 401 unauthorized never returns JSON. Just the string "Unauthorized". This results in an error I noticed when getting this setup.

Run dylanfm/render-deploy-action@status-fails
undefined:1
Unauthorized
^

SyntaxError: Unexpected token U in JSON at position 0
    at JSON.parse (<anonymous>)
    at Response.json (/home/runner/work/_actions/dylanfm/render-deploy-action/status-fails/dist/index.js:6968:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

If the API docs aren't right for this particular error case, maybe the code needs a special case for 401 responses that doesn't expect JSON.

Comparison to another error using curl shows that at least 404 errors do return JSON (although not the "id" property from docs).

$ curl --request POST --url https://api.render.com/v1/services/serviceId/deploys --header 'Accept: application/json' --header 'Content-Type: application/json' --header 'Authorization: Bearer abc'
Unauthorized
$ curl --request POST --url https://api.render.com/v1/services/serviceId/deploys --header 'Accept: application/json' --header 'Content-Type: application/json' --header 'Authorization: Bearer rnd_aRealKey'
{"message":"not found: service serviceId"}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great spot, I've raised it with our engineering team. It does seem that the Unauthorized one is the only one that returns plain text which isn't as it's documented.

@MorenoMdz
Copy link

@DylanFM mind to fix the conflicts? This fix would be appreciated!

@DylanFM
Copy link
Author

DylanFM commented Jun 6, 2023

Hi @MorenoMdz. Does the update @johnbeynon made in 4545b7c cover your needs? This PR may be OK to close.

@MorenoMdz
Copy link

For me it still shows success in the job even when it 401.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants