Skip to content

Commit 9ec67f7

Browse files
committed
Fix response handler
1 parent f0275f2 commit 9ec67f7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

validator/remote/src/main/java/tech/pegasys/teku/validator/remote/typedef/ResponseHandler.java

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ public ResponseHandler<TObject> withHandler(
7878
return this;
7979
}
8080

81+
public ResponseHandler<TObject> withHandler(
82+
final Handler<TObject> handler, final int... responseCodes) {
83+
for (final int responseCode : responseCodes) {
84+
handlers.put(responseCode, handler);
85+
}
86+
return this;
87+
}
88+
8189
private Optional<TObject> defaultOkHandler(final Request request, final Response response)
8290
throws IOException {
8391
final ResponseBody responseBody = response.body();

validator/remote/src/main/java/tech/pegasys/teku/validator/remote/typedef/handlers/PostStateValidatorsRequest.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
import static tech.pegasys.teku.ethereum.json.types.beacon.StateValidatorDataBuilder.STATE_VALIDATORS_RESPONSE_TYPE;
1717
import static tech.pegasys.teku.ethereum.json.types.beacon.StateValidatorRequestBodyType.STATE_VALIDATOR_REQUEST_TYPE;
18+
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST;
19+
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_METHOD_NOT_ALLOWED;
20+
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NOT_FOUND;
1821
import static tech.pegasys.teku.validator.remote.apiclient.ValidatorApiMethod.GET_VALIDATORS;
1922

2023
import java.util.List;
@@ -25,6 +28,7 @@
2528
import tech.pegasys.teku.ethereum.json.types.beacon.StateValidatorData;
2629
import tech.pegasys.teku.ethereum.json.types.beacon.StateValidatorRequestBodyType;
2730
import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData;
31+
import tech.pegasys.teku.validator.remote.apiclient.PostStateValidatorsNotExistingException;
2832
import tech.pegasys.teku.validator.remote.typedef.ResponseHandler;
2933

3034
public class PostStateValidatorsRequest extends AbstractTypeDefRequest {
@@ -39,6 +43,13 @@ public Optional<ObjectAndMetaData<List<StateValidatorData>>> postStateValidators
3943
Map.of(),
4044
new StateValidatorRequestBodyType(validatorIds, List.of()),
4145
STATE_VALIDATOR_REQUEST_TYPE,
42-
new ResponseHandler<>(STATE_VALIDATORS_RESPONSE_TYPE));
46+
new ResponseHandler<>(STATE_VALIDATORS_RESPONSE_TYPE)
47+
.withHandler(
48+
(request, response) -> {
49+
throw new PostStateValidatorsNotExistingException();
50+
},
51+
SC_BAD_REQUEST,
52+
SC_NOT_FOUND,
53+
SC_METHOD_NOT_ALLOWED));
4354
}
4455
}

0 commit comments

Comments
 (0)