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,7 +190,13 @@ 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)); | ||||||
|  |     } catch (Exception ex) { | ||||||
|  |       return DaprException.wrapMono(ex); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   private <T> Mono<T> getMono(TypeRef<T> type, DaprHttp.Response r) { | ||||||
|     try { |     try { | ||||||
|       T object = objectSerializer.deserialize(r.getBody(), type); |       T object = objectSerializer.deserialize(r.getBody(), type); | ||||||
|       if (object == null) { |       if (object == null) { | ||||||
|  | @ -201,10 +207,6 @@ public class DaprClientHttp extends AbstractDaprClient { | ||||||
|     } catch (Exception ex) { |     } catch (Exception ex) { | ||||||
|       return DaprException.wrapMono(ex); |       return DaprException.wrapMono(ex); | ||||||
|     } |     } | ||||||
|       }).map(r -> new Response<>(context, r)); |  | ||||||
|     } catch (Exception 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