Skip to content

Commit

Permalink
bug(http): Process failure status codes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
berndruecker committed Dec 2, 2019
1 parent 0d0e96b commit c3f6a52
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/java/io/zeebe/http/HttpJobHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public void handle(JobClient jobClient, ActivatedJob job) throws IOException, In
final HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

if (hasFailingStatusCode(response, configurationMaps)) {
jobClient.newFailCommand(job.getKey());
jobClient.newFailCommand(job.getKey()) //
.retries(job.getRetries()-1) // simply decremenent retries for now, but we should think about it: https://github.com/zeebe-io/zeebe-http-worker/issues/22
.errorMessage( "Http request failed with " + response.statusCode() + ": " + response.body() ) //
.send().join();
} else if (hasCompletingStatusCode(response, configurationMaps)) {
final Map<String, Object> result = processResponse(job, response);
jobClient.newCompleteCommand(job.getKey()).variables(result).send().join();
Expand Down
23 changes: 21 additions & 2 deletions src/test/java/io/zeebe/http/WorkflowTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.zeebe.http;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.Assert.*;

import java.util.Collections;
import java.util.HashMap;
Expand All @@ -16,7 +17,6 @@
import org.springframework.test.context.junit4.SpringRunner;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.github.tomakehurst.wiremock.recording.SnapshotRecordResult;
import com.github.tomakehurst.wiremock.stubbing.Scenario;

import io.zeebe.client.api.response.WorkflowInstanceEvent;
Expand Down Expand Up @@ -201,7 +201,26 @@ public void shouldExposeJobKeyIfStatusCode202() {
.withRequestBody(equalToJson("{\"jobKey\":\"" + recorderJob.getKey() + "\"}")));

}


@Test
public void failOnHttpStatus400() {
stubFor(post(urlEqualTo("/api")).willReturn(aResponse().withStatus(400)));

final WorkflowInstanceEvent workflowInstance =
createInstance(
serviceTask ->
serviceTask
.zeebeTaskHeader("url", WIRE_MOCK_RULE.baseUrl() + "/api")
.zeebeTaskHeader("method", "POST"));

Record<JobRecordValue> recorderJob = RecordingExporter.jobRecords(JobIntent.FAILED)
.withWorkflowInstanceKey(workflowInstance.getWorkflowInstanceKey())
.getFirst();

assertNotNull(recorderJob.getValue().getErrorMessage());
assertTrue("Error message contains status code 400: " + recorderJob.getValue().getErrorMessage(), recorderJob.getValue().getErrorMessage().contains("failed with 400"));
}

@Test
public void shouldReplacePlaceholdersWithVariables() {

Expand Down

0 comments on commit c3f6a52

Please sign in to comment.