Skip to content

Commit 6f16731

Browse files
authored
Add a new parameter to HttpStep that specifies the next step when HTTP request responds with a non-OK code (#201)
1 parent e28fa13 commit 6f16731

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

samples/steps/http-get.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,26 @@ return_value:
141141
return: ${the_message.request}
142142
```
143143

144+
### HTTP Error handling
145+
146+
It is possible to specify the DSL step to follow when GET request gets a
147+
non-OK response. For that the `error` field can be used
148+
```
149+
get_message:
150+
call: http.get
151+
args:
152+
url: http://localhost:8080/guards/fail/mock-response #step that always gives 403
153+
query:
154+
var: "value"
155+
result: the_message
156+
error: error_step
157+
158+
return_value:
159+
return: ${the_message.request}
160+
161+
error_step:
162+
return: "Request failed"
163+
status: 500
164+
```
165+
144166
[Back to Guide](../GUIDE.md#Writing-DSL-files)

samples/steps/http-post.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,26 @@ return_value:
7575
return: ${the_message.response}
7676
```
7777

78+
### HTTP Error handling
79+
80+
It is possible to specify the DSL step to follow when POST request gets a
81+
non-OK response. For that the `error` field can be used
82+
```
83+
post_step:
84+
call: http.post
85+
args:
86+
url: http://localhost:8080/nonexistant
87+
contentType: plaintext
88+
plaintext:
89+
"byrokratt"
90+
result: the_message
91+
92+
return_value:
93+
return: ${the_message.request}
94+
95+
error_step:
96+
return: "Request failed"
97+
status: 500
98+
```
99+
78100
[Back to Guide](../GUIDE.md#Writing-DSL-files)

src/main/java/ee/buerokratt/ruuter/domain/steps/http/HttpStep.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,21 @@ public abstract class HttpStep extends DslStep {
3737
protected DefaultHttpDsl localHttpExceptionDsl;
3838
protected Logging logging;
3939

40+
@JsonAlias("error")
41+
protected String onErrorStep;
42+
4043
@Override
4144
protected void executeStepAction(DslInstance di) {
4245
args.checkUrl(di);
4346
ResponseEntity<Object> response = getRequestResponse(di);
4447
di.getContext().put(resultName, new HttpStepResult(args, response, MDC.get("spanId")));
4548

4649
if (!isAllowedHttpStatusCode(di, response.getStatusCodeValue())) {
47-
throw new IllegalArgumentException();
50+
if (getOnErrorStep() != null) {
51+
setNextStepName(getOnErrorStep());
52+
}
53+
else
54+
throw new IllegalArgumentException();
4855
}
4956
}
5057

0 commit comments

Comments
 (0)