Skip to content

Commit

Permalink
Handle non-JSON non-ok responses from CloudFlare cache clear (iterati…
Browse files Browse the repository at this point in the history
  • Loading branch information
rogermparent authored Sep 10, 2020
1 parent 8d036d6 commit 1a6cb02
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions scripts/clear-cloudflare-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,24 @@ module.exports = async function () {
}
)

if (!res.ok) {
throw new Error(
`CloudFlare cache clear request returned non-ok status ${res.status}: ${res.statusText}`
)
}

const body = await res.json()

if (!res.ok || !body.success) {
if (!body.success) {
throw new Error(
'CloudFlare cache clear failed! ' +
JSON.stringify(
{
status: res.status,
errors: body.errors
},
undefined,
2
)
`CloudFlare cache clear failed! ${JSON.stringify(
{
status: res.status,
errors: body.errors
},
undefined,
2
)}`
)
}

Expand Down

0 comments on commit 1a6cb02

Please sign in to comment.