From c5a850771599b9f99c6a3723b0d9a63fe9a09ea5 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Mon, 23 Sep 2024 15:01:58 +0800 Subject: [PATCH] improve credentials null check --- main.tea | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main.tea b/main.tea index 986275c..df74c84 100644 --- a/main.tea +++ b/main.tea @@ -227,6 +227,12 @@ api doRPCRequest(action: string, version: string, protocol: string, method: stri } if (!Util.equalString(authType, 'Anonymous')) { + if (Util.isUnset(@credential)) { + throw { + code = `InvalidCredentials`, + message = `Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details.` + } + } var credentialModel = @credential.getCredential(); var credentialType = credentialModel.type; if (Util.equalString(credentialType, 'bearer')) { @@ -405,6 +411,12 @@ api doROARequest(action: string, version: string, protocol: string, method: stri } if (!Util.equalString(authType, 'Anonymous')) { + if (Util.isUnset(@credential)) { + throw { + code = `InvalidCredentials`, + message = `Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details.` + } + } var credentialModel = @credential.getCredential(); var credentialType = credentialModel.type; if (Util.equalString(credentialType, 'bearer')) { @@ -584,6 +596,12 @@ api doROARequestWithForm(action: string, version: string, protocol: string, meth } if (!Util.equalString(authType, 'Anonymous')) { + if (Util.isUnset(@credential)) { + throw { + code = `InvalidCredentials`, + message = `Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details.` + } + } var credentialModel = @credential.getCredential(); var credentialType = credentialModel.type; if (Util.equalString(credentialType, 'bearer')) {