Last active
October 11, 2019 22:34
-
-
Save akhilbojedla/583a9ecaf16532aaa6cff56cbb940410 to your computer and use it in GitHub Desktop.
HelloController based on Spring WebFlux handling error with onErrorReturn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bytecodehq.routes; | |
import reactor.core.publisher.Mono; | |
import java.io.IOException; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
public class HelloController { | |
/** | |
* Returns a static message on all exceptions. | |
*/ | |
@GetMapping | |
public Mono<String> helloWorld() { | |
return Mono.<String>error(IOException::new) | |
.onErrorReturn("Error"); | |
} | |
/** | |
* Returns a static message on {@link IOException} | |
*/ | |
@GetMapping("/2") | |
public Mono<String> helloWorld2() { | |
return Mono.<String>error(IOException::new) | |
.onErrorReturn(IOException.class, "Error"); | |
} | |
/** | |
* Returns a static message based on truthfulness of predicate | |
*/ | |
@GetMapping("/3") | |
public Mono<String> helloWorld3() { | |
return Mono.<String>error(IOException::new) | |
.onErrorReturn(e -> e instanceof IOException, "Error"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment