From a0543d5b21c08342f4f2e523c8e53c31cb68cb22 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Tue, 19 Sep 2023 17:38:34 -0400 Subject: [PATCH] chore(add-preview-url-to-cloud-idp.ts) friendly error (#2170) * add friendly error * remove log --- .github/workflows/register-preview-url.yml | 2 +- scripts/add-preview-url-to-cloud-idp.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/register-preview-url.yml b/.github/workflows/register-preview-url.yml index 5271bff2d7..f4f4dc0921 100644 --- a/.github/workflows/register-preview-url.yml +++ b/.github/workflows/register-preview-url.yml @@ -12,7 +12,7 @@ on: jobs: on-deploy: runs-on: ubuntu-latest - if: github.event.deployment_status.state == 'success' && github.event.deployment_status.environment == 'Preview' + if: github.event.deployment_status.state == 'success' && github.event.deployment_status.environment == 'Preview' || github.event_name == 'workflow_dispatch' steps: - name: summary run: | diff --git a/scripts/add-preview-url-to-cloud-idp.ts b/scripts/add-preview-url-to-cloud-idp.ts index 51f6a04258..9415aef52f 100644 --- a/scripts/add-preview-url-to-cloud-idp.ts +++ b/scripts/add-preview-url-to-cloud-idp.ts @@ -29,8 +29,18 @@ async function fetchDeploymentAlias(previewUrl: string): Promise { const headers = { Authorization: `Bearer ${vercelApiToken}` } const res = await fetch(url.toString(), { headers }) + const data = await res.json() - console.log(data) + // Potential error: + // { error: { code: 'not_found', message: 'Deployment not found' } } + if (data?.error) { + console.log(data.error) + console.log( + `If the error.message is "Deployment not found", it is possible that the VERCEL_API_TOKEN GitHub repo secret is invalid. +Try rotating the value and re-running the action.` + ) + throw new Error(data.error.message) + } // NOTE: returned aliases only contain hostname, and no scheme // Scheme will need to be prepended before being passed in the