@@ -262,9 +262,7 @@ private String formatErrorMessage(@Nonnull final String body, @Nullable final St
262262 return null ;
263263 }
264264
265- if (contentType != null
266- && !contentType .isEmpty ()
267- && !contentType .regionMatches (true , 0 , "application/json" , 0 , "application/json" .length ())) {
265+ if (!errIsJsonLikeContentType (contentType )) {
268266 return null ;
269267 }
270268
@@ -300,12 +298,10 @@ private String formatErrorMessage(@Nonnull final String body, @Nullable final St
300298 // Core/Enterprise object format:
301299 // {"error":"...","data":{"error_message":"..."}}
302300 if (isV3PartialWriteError (error ) && dataNode != null && dataNode .isObject ()) {
303- final StringBuilder message = new StringBuilder (error );
304301 final String errorMessage = errNonEmptyField (dataNode , "error_message" );
305- if (errorMessage != null ) {
306- message .append (":\n \t " ).append (errorMessage );
307- }
308- return message .toString ();
302+ return errorMessage == null
303+ ? error
304+ : error + ":\n \t " + errorMessage ;
309305 }
310306
311307 return error ;
@@ -323,9 +319,7 @@ private List<InfluxDBPartialWriteException.LineError> parsePartialWriteLineError
323319 return List .of ();
324320 }
325321
326- if (contentType != null
327- && !contentType .isEmpty ()
328- && !contentType .regionMatches (true , 0 , "application/json" , 0 , "application/json" .length ())) {
322+ if (!errIsJsonLikeContentType (contentType )) {
329323 return List .of ();
330324 }
331325
@@ -383,6 +377,12 @@ private boolean isV3PartialWriteError(@Nullable final String errorMessage) {
383377 || normalized .contains ("parsing failed for write_lp endpoint" );
384378 }
385379
380+ private boolean errIsJsonLikeContentType (@ Nullable final String contentType ) {
381+ return contentType == null
382+ || contentType .isEmpty ()
383+ || contentType .regionMatches (true , 0 , "application/json" , 0 , "application/json" .length ());
384+ }
385+
386386 @ Nullable
387387 private String errNonEmptyText (@ Nullable final JsonNode node ) {
388388 if (node == null || node .isNull ()) {
0 commit comments