This is an automated email from the ASF dual-hosted git repository. pdesai pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git
The following commit(s) were added to refs/heads/master by this push: new 79ddf4a skipping response data in case of http request was successful (#981) 79ddf4a is described below commit 79ddf4afab63f7383e92157cf151bbe2dd398acd Author: Priti Desai <pde...@us.ibm.com> AuthorDate: Thu Sep 13 12:00:25 2018 -0700 skipping response data in case of http request was successful (#981) --- wskderrors/wskdeployerror.go | 9 ++++++++- wskderrors/wskdeployerror_test.go | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/wskderrors/wskdeployerror.go b/wskderrors/wskdeployerror.go index 978d1d3..207b1ad 100644 --- a/wskderrors/wskdeployerror.go +++ b/wskderrors/wskdeployerror.go @@ -196,7 +196,14 @@ func NewWhiskClientError(errorMessage string, code int, response *http.Response) if response != nil { responseData, _ := ioutil.ReadAll(response.Body) err.SetMessageFormat("%s: %d: %s: %s: %s %s: %s") - str = fmt.Sprintf(err.MessageFormat, STR_ERROR_CODE, code, errorMessage, STR_HTTP_STATUS, response.Status, STR_HTTP_BODY, string(responseData)) + // do not add body in case of a success + // when response.Status is 200, response.Body contains the entire action source code + // we should not expose the action source when the HTTP request was successful + if strings.Contains(response.Status, "200 OK") { + str = fmt.Sprintf(err.MessageFormat, STR_ERROR_CODE, code, errorMessage, STR_HTTP_STATUS, response.Status, "", "") + } else { + str = fmt.Sprintf(err.MessageFormat, STR_ERROR_CODE, code, errorMessage, STR_HTTP_STATUS, response.Status, STR_HTTP_BODY, string(responseData)) + } } err.SetMessage(str) return err diff --git a/wskderrors/wskdeployerror_test.go b/wskderrors/wskdeployerror_test.go index 57b8d74..44f7a8d 100644 --- a/wskderrors/wskdeployerror_test.go +++ b/wskderrors/wskdeployerror_test.go @@ -38,7 +38,8 @@ func TestCustomErrorOutputFormat(t *testing.T) { packageName := filepath.Base(fn) const TEST_DEFAULT_ERROR_MESSAGE = "Some bad error" const TEST_COMMAND string = "test" - const TEST_ERROR_CODE = 400 // Bad request + const TEST_ERROR_CODE = 400 // Bad request + const TEST_SUCCESS_CODE = 200 // Good request const TEST_EXISTANT_MANIFEST_FILE = "tests/dat/manifest_validate_multiline_params.yaml" const TEST_NONEXISTANT_MANIFEST_FILE = "tests/dat/missing_manifest.yaml" const TEST_INVALID_YAML_MANIFEST_FILE = "tests/dat/manifest_bad_yaml_invalid_comment.yaml" @@ -76,6 +77,19 @@ func TestCustomErrorOutputFormat(t *testing.T) { assert.Equal(t, expectedResult, actualResult) /* + * WhiskClientError + */ + err21 := NewWhiskClientError("", TEST_SUCCESS_CODE, nil) + actualResult = strings.TrimSpace(err21.Error()) + expectedResult = fmt.Sprintf("%s [%d]: [%s]: %s: %d:", + packageName, + err21.LineNum, + ERROR_WHISK_CLIENT_ERROR, + STR_ERROR_CODE, + TEST_SUCCESS_CODE) + assert.Equal(t, expectedResult, actualResult) + + /* * WhiskClientInvalidConfigError */ err3 := NewWhiskClientInvalidConfigError(TEST_DEFAULT_ERROR_MESSAGE)