We encountered this today in our system when changes to our merchant account and public/private keys resulted in HTTP 403 errors in requests to generate client tokens.
We log results with a log statement similar to
log.error("Failed to get BraintreeToken. Error message: {}", e.getMessage());
which obviously was not very helpful in debugging.
One solution would be to pass the request's responseMessage from HttpURLConnection#getResponseMessage() to the call to throwExceptionIfErrorStatusCode(int, String), however that may not work well with the URLDecoder#decode() performed on message.
General information
Issue description
When
Http#throwExceptionIfErrorStatusCode(int code, String message)
is called inHttp#httpRequest()
, themessage
parameter is alwaysnull
as seen here: https://github.com/braintree/braintree_java/blob/master/src/main/java/com/braintreegateway/util/Http.java#L150This leads to difficult debugging due to a lack of information when attempting to access the thrown exception's message via
Exception#getMessage()
, particularly when the exception is anAuthorizationException
, whose message is set to the variabledecodedMessage
, which is initialised tonull
and its value is only set ifmessage
is notnull
. See https://github.com/braintree/braintree_java/blob/master/src/main/java/com/braintreegateway/util/Http.java#L384 and https://github.com/braintree/braintree_java/blob/master/src/main/java/com/braintreegateway/util/Http.java#L399We encountered this today in our system when changes to our merchant account and public/private keys resulted in HTTP 403 errors in requests to generate client tokens.
We log results with a log statement similar to
log.error("Failed to get BraintreeToken. Error message: {}", e.getMessage());
which obviously was not very helpful in debugging.One solution would be to pass the request's responseMessage from
HttpURLConnection#getResponseMessage()
to the call tothrowExceptionIfErrorStatusCode(int, String)
, however that may not work well with theURLDecoder#decode()
performed onmessage
.