From 3c2cf886df0ba4a7dbdbcccc0a9b0b3a2bc49f04 Mon Sep 17 00:00:00 2001 From: tq0fqeu Date: Mon, 21 Dec 2020 14:43:34 +0800 Subject: [PATCH 1/2] feat: pretty and to be compatible with some not standard error messages such as Container Service --- lib/aliyunsdkcore/roa_client.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/aliyunsdkcore/roa_client.rb b/lib/aliyunsdkcore/roa_client.rb index 56555cb..5012601 100644 --- a/lib/aliyunsdkcore/roa_client.rb +++ b/lib/aliyunsdkcore/roa_client.rb @@ -48,8 +48,8 @@ def request(method:, uri:, params: {}, body: {}, headers: {}, options: {}) response_content_type = response.headers['Content-Type'] || '' if response_content_type.start_with?('application/json') if response.status >= 400 - result = JSON.parse(response.body) - raise StandardError, "code: #{response.status}, #{result['Message']} requestid: #{result['RequestId']}" + result = JSON.parse(response.body).transform_keys(&:downcase) + raise StandardError, "status: #{response.status}, code: #{result['code']}, message: #{result['message']}, requestid: #{result['requestid']}" end end From 700c3a449da20144c80543f3f38a9f5b041323e2 Mon Sep 17 00:00:00 2001 From: tq0fqeu Date: Tue, 22 Dec 2020 13:44:14 +0800 Subject: [PATCH 2/2] fix: fix ut err --- spec/roa_client_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/roa_client_spec.rb b/spec/roa_client_spec.rb index 2118e5c..3256428 100644 --- a/spec/roa_client_spec.rb +++ b/spec/roa_client_spec.rb @@ -147,7 +147,7 @@ .to_return(status: status, headers: headers, body: body) expect { roa_client.get(uri: '/', headers: { 'content-type': 'application/json' }) - }.to raise_error(StandardError, 'code: 400, error message requestid: requestid') + }.to raise_error(StandardError, 'status: 400, code: errorcode, message: error message, requestid: requestid') end end