-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log less #2718
base: master
Are you sure you want to change the base?
Log less #2718
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
"net/http/httputil" | ||
"net/url" | ||
"os" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
@@ -236,25 +237,31 @@ func submit( | |
if err != nil { | ||
return nil, resp, fmt.Errorf("%w: %s", errorutils.ErrFailedBodyRead, err.Error()) | ||
} | ||
sbody := string(body) | ||
for _, p := range []string{`"description":\s*"[^"]+"\s*,?`, `"\w+Country":\s*"[^"]+"\s*,?`} { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: do we have an example of the response we are trying to redact this from? we could add an example response to a test, I wonder if we can use an or instead of having two separate passes or the regex There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test with an example object. |
||
re := regexp.MustCompile(p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: instead of compiling the regex on every call of the method and for each value can we just compile them once and reuse There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the readability cost of moving the regex out of here is worse than the performance cost of recompiling it. This call flow spends most of its time waiting for i/o and regex compilation time will be negligible. |
||
sbody = re.ReplaceAllString(sbody, "") | ||
} | ||
sbody = regexp.MustCompile(`,}`).ReplaceAllString(sbody, "}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: could we use |
||
|
||
if logger != nil { | ||
logger.Debug(). | ||
Str("path", "github.com/brave-intl/bat-go/wallet/provider/uphold"). | ||
Str("type", "http.Response"). | ||
Int("status", resp.StatusCode). | ||
Str("headers", string(jsonHeaders)). | ||
Msg(string(body)) | ||
Msg(sbody) | ||
} | ||
|
||
if resp.StatusCode/100 != 2 { | ||
var uhErr upholdError | ||
if json.Unmarshal(body, &uhErr) != nil { | ||
return nil, resp, fmt.Errorf("Error %d, %s", resp.StatusCode, body) | ||
if json.Unmarshal([]byte(sbody), &uhErr) != nil { | ||
return nil, resp, fmt.Errorf("Error %d, %s", resp.StatusCode, sbody) | ||
} | ||
uhErr.RequestID = resp.Header.Get("Request-Id") | ||
return nil, resp, uhErr | ||
} | ||
return body, resp, nil | ||
return []byte(sbody), resp, nil | ||
} | ||
|
||
type createCardRequest struct { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: could we extract this block into a function so we can test it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done.