From b2e854afcd0be0d335b708780ca6be7bfac91184 Mon Sep 17 00:00:00 2001 From: fabgo Date: Thu, 26 Sep 2024 11:37:05 -0700 Subject: [PATCH] ENG-2677 Better error-handling of expired token (#115) Improved the error-handling if 'gcloud auth print-access-token' does not return a valid access token. --- src/plugins/google/ssh-key.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/google/ssh-key.ts b/src/plugins/google/ssh-key.ts index 93d331a..fea1c95 100644 --- a/src/plugins/google/ssh-key.ts +++ b/src/plugins/google/ssh-key.ts @@ -59,7 +59,15 @@ export const importSshKey = async ( }); if (!response.ok) { - throw `Import of SSH public key failed. HTTP error ${response.status}: ${await response.text()}`; + if (debug) { + print2(`HTTP error ${response.status}: ${await response.text()}`); + } + + if (response.status === 401) { + throw `Authentication failed. Please login to Google Cloud CLI with 'gcloud auth login'`; + } else { + throw `Import of SSH public key failed.`; + } } const data: ImportSshPublicKeyResponse = await response.json();