Skip to content

Commit

Permalink
fix: error extraction for errors in destination transformation (#3499)
Browse files Browse the repository at this point in the history
* fix: error extraction for errors in destination transformation

Signed-off-by: Sai Sankeerth <sanpj2292@github.com>

* chore: replace the string with constant

Signed-off-by: Sai Sankeerth <sanpj2292@github.com>

---------

Signed-off-by: Sai Sankeerth <sanpj2292@github.com>
Co-authored-by: Sai Sankeerth <sanpj2292@github.com>
  • Loading branch information
sanpj2292 and Sai Sankeerth authored Jun 15, 2023
1 parent f612aae commit 5c43457
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions enterprise/reporting/error_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

const (
responseKey = "response"
errorKey = "error"
spaceStr = " "

destinationResponseKey = "destinationResponse"
Expand All @@ -29,7 +30,7 @@ var (
spaceRegex = regexp.MustCompile(`\s+`)
whitespacesRegex = regexp.MustCompile("[ \t\n\r]*") // used in checking if string is a valid json to remove extra-spaces

defaultErrorMessageKeys = []string{"message", "description", "detail", "title", "error", "error_message"}
defaultErrorMessageKeys = []string{"message", "description", "detail", "title", errorKey, "error_message"}
)

type ExtractorHandle struct {
Expand Down Expand Up @@ -83,7 +84,7 @@ func (ext *ExtractorHandle) getSimpleMessage(jsonStr string) string {
return strings.Split(erResStr, "\n")[0]
}
return ""
case responseKey:
case responseKey, errorKey:
if IsJSON(erResStr) {
var unmarshalledJson interface{}
unmarshalledErr := json.Unmarshal([]byte(erResStr), &unmarshalledJson)
Expand Down
8 changes: 8 additions & 0 deletions enterprise/reporting/reporting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ var tcs = []getValTc{
inputStr: `{"response":"{\n\t\t\t\tError: invalid character 'P' looking for beginning of value,\n\t\t\t\t(trRespStCd, trRespBody): (504, Post \"http://transformer.rudder-us-east-1b-blue/v0/destinations/google_adwords_enhanced_conversions/proxy\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)),\n\t\t\t}","firstAttemptedAt":"2023-03-30T17:24:58.068Z","content-type":"text/plain; charset=utf-8"}`,
expected: "{\n\t\t\t\tError: invalid character 'P' looking for beginning of value,\n\t\t\t\t(trRespStCd, trRespBody): (504, Post \"http://transformer.rudder-us-east-1b-blue/v0/destinations/google_adwords_enhanced_conversions/proxy\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)),\n\t\t\t}",
},
{
inputStr: `{"error":"{\"message\":\"some random message\",\"destinationResponse\":{\"error\":{\"message\":\"Unhandled random error\",\"type\":\"RandomException\",\"code\":5,\"error_subcode\":12,\"fbtrace_id\":\"facebook_px_trace_id_10\"},\"status\":412}}","firstAttemptedAt":"2023-04-20T17:24:58.068Z","content-type":"text/plain; charset=utf-8"}`,
expected: "Unhandled random error",
},
{
inputStr: `{"error":"unknown error occurred","firstAttemptedAt":"2023-04-21T17:24:58.068Z","content-type":"text/plain; charset=utf-8"}`,
expected: "unknown error occurred",
},
}

func TestGetErrorMessageFromResponse(t *testing.T) {
Expand Down

0 comments on commit 5c43457

Please sign in to comment.