@@ -163,49 +163,6 @@ public static BodyHandler<Void> discarding() {
163163 return responseInfo -> null ;
164164 }
165165
166- /**
167- * Throws on HTTP error using the provided mapper, or apply the provided body handler.
168- * @param handler the body handler to apply on non-error HTTP responses
169- * @param isSuccess a callback determining error cases
170- * @param exceptionMapper the exception mapper
171- * @return the body handler
172- * @param <T> the type of the body handler
173- */
174- public static <T > Response .BodyHandler <T > throwOnError (
175- final Response .BodyHandler <T > handler ,
176- final Function <Response .ResponseInfo , Boolean > isSuccess ,
177- final Function <Response .ResponseInfo , ClientHttpException > exceptionMapper
178- ) {
179- return responseinfo -> {
180- if (!isSuccess .apply (responseinfo )) {
181- throw exceptionMapper .apply (responseinfo );
182- }
183- return handler .apply (responseinfo );
184- };
185- }
186-
187- /**
188- * Throws on HTTP error, or apply the provided body handler.
189- * @param handler the body handler to apply on non-error HTTP responses
190- * @param isSuccess a callback determining error cases
191- * @return the body handler
192- * @param <T> the type of the body handler
193- */
194- public static <T > Response .BodyHandler <T > throwOnError (
195- final Response .BodyHandler <T > handler ,
196- final Function <Response .ResponseInfo , Boolean > isSuccess
197- ) {
198- final Function <Response .ResponseInfo , ClientHttpException > defaultMapper = responseInfo ->
199- new ClientHttpException (
200- "An HTTP error has been returned, with status code " + responseInfo .statusCode (),
201- responseInfo .uri (),
202- responseInfo .statusCode (),
203- responseInfo .headers (),
204- new String (responseInfo .body ().array (), StandardCharsets .UTF_8 )
205- );
206- return throwOnError (handler , isSuccess , defaultMapper );
207- }
208-
209166 private BodyHandlers () {
210167 // Prevent instantiation
211168 }
0 commit comments