import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.reactive.function.client.WebClientResponseException;
+import org.springframework.web.reactive.function.client.WebClientResponseException.NotFound;
import reactor.core.publisher.Mono;
@GetMapping(path = { "", "/" }, produces = MediaType.TEXT_PLAIN_VALUE)
public Mono<String> fetch(@RequestParam String path)
{
- return service.getRemoteText(path);
+ return
+ service
+ .getRemoteText(path)
+ .onErrorResume(t ->
+ {
+ if(t.getClass().equals(NotFound.class))
+ return Mono.error(t);
+
+ return
+ Mono.error(
+ WebClientResponseException.create(
+ 503,
+ "Service Unavailable - Cause: " + t.getMessage(),
+ null,
+ null,
+ null));
+ });
}
}