mirror of https://github.com/dapr/java-sdk.git
refactor to move duplicate code to method (#429)
Signed-off-by: Arghya Sadhu <arghya88@gmail.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
This commit is contained in:
parent
b5dd421142
commit
4c1773c8cd
|
|
@ -190,18 +190,20 @@ public class DaprClientHttp extends AbstractDaprClient {
|
||||||
byte[] serializedRequestBody = objectSerializer.serialize(request);
|
byte[] serializedRequestBody = objectSerializer.serialize(request);
|
||||||
Mono<DaprHttp.Response> response = this.client.invokeApi(httMethod, path,
|
Mono<DaprHttp.Response> response = this.client.invokeApi(httMethod, path,
|
||||||
httpExtension.getQueryString(), serializedRequestBody, metadata, context);
|
httpExtension.getQueryString(), serializedRequestBody, metadata, context);
|
||||||
return response.flatMap(r -> {
|
return response.flatMap(r -> getMono(type, r)).map(r -> new Response<>(context, r));
|
||||||
try {
|
} catch (Exception ex) {
|
||||||
T object = objectSerializer.deserialize(r.getBody(), type);
|
return DaprException.wrapMono(ex);
|
||||||
if (object == null) {
|
}
|
||||||
return Mono.empty();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return Mono.just(object);
|
private <T> Mono<T> getMono(TypeRef<T> type, DaprHttp.Response r) {
|
||||||
} catch (Exception ex) {
|
try {
|
||||||
return DaprException.wrapMono(ex);
|
T object = objectSerializer.deserialize(r.getBody(), type);
|
||||||
}
|
if (object == null) {
|
||||||
}).map(r -> new Response<>(context, r));
|
return Mono.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Mono.just(object);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return DaprException.wrapMono(ex);
|
return DaprException.wrapMono(ex);
|
||||||
}
|
}
|
||||||
|
|
@ -258,18 +260,7 @@ public class DaprClientHttp extends AbstractDaprClient {
|
||||||
String httpMethod = DaprHttp.HttpMethods.POST.name();
|
String httpMethod = DaprHttp.HttpMethods.POST.name();
|
||||||
Mono<DaprHttp.Response> response = this.client.invokeApi(
|
Mono<DaprHttp.Response> response = this.client.invokeApi(
|
||||||
httpMethod, url.toString(), null, payload, null, context);
|
httpMethod, url.toString(), null, payload, null, context);
|
||||||
return response.flatMap(r -> {
|
return response.flatMap(r -> getMono(type, r)).map(r -> new Response<>(context, r));
|
||||||
try {
|
|
||||||
T object = objectSerializer.deserialize(r.getBody(), type);
|
|
||||||
if (object == null) {
|
|
||||||
return Mono.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Mono.just(object);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return DaprException.wrapMono(ex);
|
|
||||||
}
|
|
||||||
}).map(r -> new Response<>(context, r));
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return DaprException.wrapMono(ex);
|
return DaprException.wrapMono(ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue