@@ -1715,11 +1715,17 @@ private String appendRateLimitValues(String response, HttpResponse httpResponse)
17151715 return StringUtils .EMPTY ;
17161716 }
17171717
1718- String rateLimitData =
1719- String .format (RATE_LIMIT_JSON_STRUCT , getSimpleHeaderValue (HDR_RATE_LIMIT , httpResponse ),
1720- getSimpleHeaderValue (HDR_RATE_REMAINING , httpResponse ),
1721- getDateString (getSimpleHeaderValue (HDR_RATE_RESET , httpResponse ), DATE_FORMAT ));
1718+ // Occasionally the DigitalOcean API will fail to send rate limit headers.
1719+ // Simply omit rate limit data in that case.
1720+ String rateLimit = getSimpleHeaderValue (HDR_RATE_LIMIT , httpResponse );
1721+ String rateRemaining = getSimpleHeaderValue (HDR_RATE_REMAINING , httpResponse );
1722+ String rateReset = getSimpleHeaderValue (HDR_RATE_RESET , httpResponse );
1723+ if (rateLimit == null || rateRemaining == null || rateReset == null ) {
1724+ return response ;
1725+ }
17221726
1727+ String rateLimitData = String .format (RATE_LIMIT_JSON_STRUCT ,
1728+ rateLimit , rateRemaining , getDateString (rateReset , DATE_FORMAT ));
17231729 log .debug ("RateLimitData:: {}" , rateLimitData );
17241730
17251731 return StringUtils .substringBeforeLast (response , "}" ) + ", " + rateLimitData + "}" ;
@@ -1740,18 +1746,20 @@ private String getDateString(String epochString, String dateFormat) {
17401746 * Easy method for HTTP header values (first/last)
17411747 */
17421748 private String getSimpleHeaderValue (String header , HttpResponse httpResponse , boolean first ) {
1743- String value = StringUtils .EMPTY ;
17441749 if (StringUtils .isBlank (header )) {
1745- return value ;
1750+ return StringUtils . EMPTY ;
17461751 }
17471752
1753+ Header h ;
17481754 if (first ) {
1749- value = httpResponse .getFirstHeader (header ). getValue ( );
1755+ h = httpResponse .getFirstHeader (header );
17501756 } else {
1751- value = httpResponse .getLastHeader (header ). getValue ( );
1757+ h = httpResponse .getLastHeader (header );
17521758 }
1753-
1754- return value ;
1759+ if (h == null ) {
1760+ return null ;
1761+ }
1762+ return h .getValue ();
17551763 }
17561764
17571765 /**
0 commit comments