本文整理了Java中reactor.core.publisher.Mono.error()
方法的一些代码示例,展示了Mono.error()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.error()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:error
[英]Create a Mono that terminates with the specified error immediately after being subscribed to.
[中]创建一个Mono,在订阅后立即以指定错误终止。
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> setComplete() {
return Mono.error(new UnsupportedOperationException());
}
}
代码示例来源:origin: spring-projects/spring-framework
private static <T> Mono<T> wrapException(Supplier<Mono<T>> supplier) {
try {
return supplier.get();
}
catch (Throwable ex) {
return Mono.error(ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Apply the exception handler and return the alternative result.
* @param failure the exception
* @return the new result or the same error if there is no exception handler
*/
public Mono<HandlerResult> applyExceptionHandler(Throwable failure) {
return (this.exceptionHandler != null ? this.exceptionHandler.apply(failure) : Mono.error(failure));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
return Mono.error(ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> handle(ServerWebExchange exchange) {
if (this.raise) {
throw this.exception;
}
return Mono.error(this.exception);
}
}
代码示例来源:origin: spring-projects/spring-framework
private Mono<?> decodeData(String data, ResolvableType dataType, Map<String, Object> hints) {
if (String.class == dataType.resolve()) {
return Mono.just(data.substring(0, data.length() - 1));
}
if (this.decoder == null) {
return Mono.error(new CodecException("No SSE decoder configured and the data is not String."));
}
byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
Mono<DataBuffer> input = Mono.just(bufferFactory.wrap(bytes));
return this.decoder.decodeToMono(input, dataType, MediaType.TEXT_EVENT_STREAM, hints);
}
代码示例来源:origin: spring-projects/spring-framework
private <R> Mono<R> createNotFoundError() {
return Mono.defer(() -> {
Exception ex = new ResponseStatusException(HttpStatus.NOT_FOUND, "No matching handler");
return Mono.error(ex);
});
}
代码示例来源:origin: spring-projects/spring-framework
@Bean
public WebHandler webHandler() {
return exchange -> Mono.error(new Exception());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
if (this.body != null) {
return Mono.error(new IllegalStateException("Multiple calls to writeWith() not supported"));
}
this.body = Flux.just(generateHeaders()).concatWith(body);
// We don't actually want to write (just save the body Flux)
return Mono.empty();
}
代码示例来源:origin: spring-projects/spring-framework
private static <P extends Publisher<?>, M extends ReactiveHttpOutputMessage> Mono<Void> writeWithMessageWriters(
M outputMessage, BodyInserter.Context context, P body, ResolvableType bodyType) {
MediaType mediaType = outputMessage.getHeaders().getContentType();
return context.messageWriters().stream()
.filter(messageWriter -> messageWriter.canWrite(bodyType, mediaType))
.findFirst()
.map(BodyInserters::cast)
.map(writer -> write(body, bodyType, mediaType, outputMessage, context, writer))
.orElseGet(() -> Mono.error(unsupportedError(bodyType, context, mediaType)));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Object> readMono(
ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
// We're ahead of String + "*/*"
// Let's see if we can aggregate the output (lest we time out)...
if (elementType.resolve() == String.class) {
Flux<DataBuffer> body = message.getBody();
return stringDecoder.decodeToMono(body, elementType, null, null).cast(Object.class);
}
return Mono.error(new UnsupportedOperationException(
"ServerSentEventHttpMessageReader only supports reading stream of events as a Flux"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-17473
public void onStatusWithMonoErrorAndBodyNotConsumed() {
RuntimeException ex = new RuntimeException("response error");
testOnStatus(ex, response -> Mono.error(ex));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> close(CloseStatus status) {
try {
CloseReason.CloseCode code = CloseCodes.getCloseCode(status.getCode());
getDelegate().close(new CloseReason(code, status.getReason()));
}
catch (IOException ex) {
return Mono.error(ex);
}
return Mono.empty();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Void> handle(ServerWebExchange exchange) {
if (exchange.getRequest().getURI().getPath().equals("/form-parts")) {
return assertGetFormParts(exchange);
}
return Mono.error(new AssertionError());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Object> getHandlerInternal(ServerWebExchange exchange) {
PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();
Object handler;
try {
handler = lookupHandler(lookupPath, exchange);
}
catch (Exception ex) {
return Mono.error(ex);
}
return Mono.justOrEmpty(handler);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void failure() {
Throwable expected = new IllegalStateException("oops");
AtomicReference<Object> actual = new AtomicReference<>();
ListenableFuture<String> future = new MonoToListenableFutureAdapter<>(Mono.error(expected));
future.addCallback(actual::set, actual::set);
assertEquals(expected, actual.get());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void onStatusWithMonoErrorAndBodyConsumed() {
RuntimeException ex = new RuntimeException("response error");
testOnStatus(ex, response -> response.bodyToMono(Void.class).then(Mono.error(ex)));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void errorBeforeFirstItem() throws Exception {
IllegalStateException error = new IllegalStateException("boo");
Mono<Void> completion = Mono.<String>error(error).as(this::sendOperator);
Signal<Void> signal = completion.materialize().block();
assertNotNull(signal);
assertSame("Unexpected signal: " + signal, error, signal.getThrowable());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void skipUntilByteCountErrorInFlux() {
DataBuffer foo = stringBuffer("foo");
Flux<DataBuffer> flux =
Flux.just(foo).concatWith(Mono.error(new RuntimeException()));
Flux<DataBuffer> result = DataBufferUtils.skipUntilByteCount(flux, 3L);
StepVerifier.create(result)
.expectError(RuntimeException.class)
.verify(Duration.ofSeconds(5));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void encodeError() throws Exception {
Mono<Pojo> input = Mono.error(new InputException());
testEncode(input, Pojo.class, step -> step
.expectError(InputException.class)
.verify());
}
内容来源于网络,如有侵权,请联系作者删除!