@@ -63,18 +63,6 @@ public class SolidClient {
6363 this .fetchAfterWrite = fetchAfterWrite ;
6464 }
6565
66- private static Function <Response .ResponseInfo , ClientHttpException > httpExceptionMapper (final String message ) {
67- return res -> {
68- return SolidClientException .handle (
69- message ,
70- res .uri (),
71- res .statusCode (),
72- res .headers (),
73- new String (res .body ().array (), StandardCharsets .UTF_8 )
74- );
75- };
76- }
77-
7866 /**
7967 * Create a session-scoped client.
8068 *
@@ -137,12 +125,18 @@ public <T extends Resource> CompletionStage<T> read(final URI identifier, final
137125 final Request request = builder .build ();
138126 return client .send (
139127 request ,
140- Response .BodyHandlers .throwOnError (
141- Response .BodyHandlers .ofByteArray (),
142- (r ) -> Response .isSuccess (r .statusCode ()),
143- httpExceptionMapper ("Reading resource failed." )
144- )
128+ Response .BodyHandlers .ofByteArray ()
145129 ).thenApply (response -> {
130+ if (!Response .isSuccess (response .statusCode ())) {
131+ throw SolidClientException .handle (
132+ "Reading resource failed." ,
133+ response .uri (),
134+ response .statusCode (),
135+ response .headers (),
136+ new String (response .body (), StandardCharsets .UTF_8 )
137+ );
138+ }
139+
146140 final String contentType = response .headers ().firstValue (CONTENT_TYPE )
147141 .orElse ("application/octet-stream" );
148142 try {
@@ -285,15 +279,22 @@ public <T extends Resource> CompletionStage<Void> delete(final T resource, final
285279 defaultHeaders .firstValue (USER_AGENT ).ifPresent (agent -> builder .setHeader (USER_AGENT , agent ));
286280 headers .firstValue (USER_AGENT ).ifPresent (agent -> builder .setHeader (USER_AGENT , agent ));
287281
282+
288283 return client .send (
289284 builder .build (),
290- Response .BodyHandlers .throwOnError (
291- Response .BodyHandlers .ofByteArray (),
292- (r ) -> Response .isSuccess (r .statusCode ()),
293- httpExceptionMapper ("Unable to delete resource." )
294- )
295- )
296- .thenAccept (o -> { /* no-op */ });
285+ Response .BodyHandlers .ofByteArray ()
286+ ).thenApply (response -> {
287+ if (!Response .isSuccess (response .statusCode ())) {
288+ throw SolidClientException .handle (
289+ "Deleting resource failed." ,
290+ response .uri (),
291+ response .statusCode (),
292+ response .headers (),
293+ new String (response .body (), StandardCharsets .UTF_8 )
294+ );
295+ }
296+ return null ;
297+ });
297298 }
298299
299300 /**
0 commit comments