From 24793e510629caee51a71a25ea12f1b9ec9e7646 Mon Sep 17 00:00:00 2001 From: Brandur Date: Tue, 18 Jun 2019 15:45:15 +0200 Subject: [PATCH] Log only to info on 402 errors from Stripe As discussed in #869, breaks apart how Stripe errors are logged so that status 402 errors go to info instead of error. This is meant to signal that those errors are probably prompted by user data (as opposed to sending invalid parameters or something), and handling them differently allows integrations to avoid filling their error logs with messages that they can't really prevent. Fixes #869. --- stripe.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/stripe.go b/stripe.go index 098d99edeb..da6347f626 100644 --- a/stripe.go +++ b/stripe.go @@ -486,7 +486,25 @@ func (s *BackendImplementation) ResponseToError(res *http.Response, resBody []by } raw.E.Err = typedError - s.LeveledLogger.Errorf("Error encountered from Stripe: %v", raw.E.Error) + // The Stripe API makes a distinction between errors that were caused by + // invalid parameters or something else versus those that occurred + // *despite* valid parameters, the latter coming back with status 402. + // + // On a 402, log to info so as to not make an integration's log noisy with + // error messages that they don't have much control over. + // + // Note I use the constant 402 here instead of an `http.Status*` constant + // because technically 402 is "Payment required". The Stripe API doesn't + // comply to the letter of the specification and uses it in a broader + // sense. + if res.StatusCode == 402 { + s.LeveledLogger.Infof("User-compelled request error from Stripe: %v", + raw.E.Error) + } else { + s.LeveledLogger.Errorf("Request error from Stripe: %v", + raw.E.Error) + } + return raw.E.Error }