Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public static Publisher<?> processRequest(FunctionWrapper wrapper, Object argume
Object result = function.apply(inputMessage);
if (function.isConsumer()) {
if (result instanceof Publisher && !function.isComposed()) {
Mono.from((Publisher) result).subscribe();
Mono.from((Publisher) result).subscribe(null, ex -> logger.error("Consumer '"
+ function.getFunctionDefinition() + "' failed to process the request", (Throwable) ex));
}
return "DELETE".equals(wrapper.getMethod()) ?
Mono.empty() : Mono.just(ResponseEntity.accepted().headers(HeaderUtils.sanitize(headers, ignoredHeaders, requestOnlyHeaders)).build());
Expand All @@ -182,8 +183,7 @@ public static Publisher<?> processRequest(FunctionWrapper wrapper, Object argume
}

if (pResult instanceof Flux flux) {
pResult = flux.onErrorContinue((e, v) -> logger.error("Failed to process a value of type "
+ (v == null ? null : v.getClass().getName()), (Throwable) e)).collectList();
pResult = flux.collectList();
}
pResult = Mono.from(pResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ public void wordsJson() throws Exception {

@Test
public void errorJson() throws Exception {
assertThat(this.rest
ResponseEntity<String> result = this.rest
.exchange(RequestEntity.get(new URI("/bang"))
.accept(MediaType.APPLICATION_JSON).build(), String.class)
.getBody()).isEqualTo("[\"foo\"]");
.accept(MediaType.APPLICATION_JSON).build(), String.class);
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(result.getBody()).doesNotContain("foo");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public void wordsJson() throws Exception {
}

@Test
@Disabled("Fix error handling")
public void errorJson() throws Exception {
assertThat(this.rest
ResponseEntity<String> result = this.rest
.exchange(RequestEntity.get(new URI("/bang"))
.accept(MediaType.APPLICATION_JSON).build(), String.class)
.getBody()).isEqualTo("[\"foo\"]");
.accept(MediaType.APPLICATION_JSON).build(), String.class);
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(result.getBody()).doesNotContain("foo");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import reactor.core.publisher.Mono;

import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
import org.springframework.cloud.function.web.FunctionHttpProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.Message;
import org.springframework.web.server.ResponseStatusException;

Expand Down Expand Up @@ -135,6 +140,25 @@ void clientCannotSupplyOrOverwriteFrameworkHeaders() {
.doesNotContainKeys("Scf-Func-Name", "scf-sink-url", "lambda-runtime");
}

@Test
@ExtendWith(OutputCaptureExtension.class)
void consumerFailureIsLogged(CapturedOutput output) {
FunctionInvocationWrapper function = mock(FunctionInvocationWrapper.class);
when(function.isConsumer()).thenReturn(true);
when(function.getFunctionDefinition()).thenReturn("failing");
when(function.apply(org.mockito.ArgumentMatchers.any()))
.thenReturn(Mono.error(new IllegalStateException("boom")));
FunctionWrapper wrapper = new FunctionWrapper(function, "POST");
wrapper.setHeaders(new HttpHeaders());

Object response = Mono.from(FunctionWebRequestProcessingHelper.processRequest(wrapper, "hello", false,
java.util.List.of(), java.util.List.of())).block();

assertThat(((ResponseEntity<?>) response).getStatusCode()).isEqualTo(HttpStatus.ACCEPTED);
assertThat(output).contains("Consumer 'failing' failed to process the request")
.doesNotContain("onErrorDropped");
}

@Test
void reservedHeaderNamesAreRecognisedIgnoringCase() {
assertThat(HeaderUtils.isReservedHeader("http_request_param")).isTrue();
Expand Down
Loading