Search in sources :

Example 1 with SC_BAD_REQUEST

use of tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST in project teku by ConsenSys.

the class PostVoluntaryExit method handle.

@OpenApi(path = ROUTE, method = HttpMethod.POST, summary = "Submit signed voluntary exit", tags = { TAG_BEACON }, description = "Submits signed voluntary exit object to node's pool and if it passes validation node MUST broadcast it to network.", requestBody = @OpenApiRequestBody(content = { @OpenApiContent(from = SignedVoluntaryExit.class) }), responses = { @OpenApiResponse(status = RES_OK, description = "Signed voluntary exit has been successfully validated, added to the pool, and broadcast."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid voluntary exit, it will never pass validation so it's rejected"), @OpenApiResponse(status = RES_INTERNAL_ERROR) })
@Override
public void handle(final Context ctx) throws Exception {
    try {
        final SignedVoluntaryExit exit = parseRequestBody(ctx.body(), SignedVoluntaryExit.class);
        ctx.future(nodeDataProvider.postVoluntaryExit(exit).thenApplyChecked(result -> handleResponseContext(ctx, result)));
    } catch (final IllegalArgumentException e) {
        LOG.debug("Voluntary exit failed", e);
        ctx.json(BadRequest.badRequest(jsonProvider, e.getMessage()));
        ctx.status(SC_BAD_REQUEST);
    }
}
Also used : SC_BAD_REQUEST(tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST) HttpMethod(io.javalin.plugin.openapi.annotations.HttpMethod) SignedVoluntaryExit(tech.pegasys.teku.api.schema.SignedVoluntaryExit) AbstractHandler(tech.pegasys.teku.beaconrestapi.handlers.AbstractHandler) BadRequest(tech.pegasys.teku.beaconrestapi.schema.BadRequest) TAG_BEACON(tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON) OpenApiContent(io.javalin.plugin.openapi.annotations.OpenApiContent) ValidationResultCode(tech.pegasys.teku.statetransition.validation.ValidationResultCode) RES_INTERNAL_ERROR(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_INTERNAL_ERROR) Logger(org.apache.logging.log4j.Logger) RES_BAD_REQUEST(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_BAD_REQUEST) Context(io.javalin.http.Context) OpenApiResponse(io.javalin.plugin.openapi.annotations.OpenApiResponse) RES_OK(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_OK) JsonProvider(tech.pegasys.teku.provider.JsonProvider) NodeDataProvider(tech.pegasys.teku.api.NodeDataProvider) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi) OpenApiRequestBody(io.javalin.plugin.openapi.annotations.OpenApiRequestBody) LogManager(org.apache.logging.log4j.LogManager) DataProvider(tech.pegasys.teku.api.DataProvider) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) SC_OK(tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK) SignedVoluntaryExit(tech.pegasys.teku.api.schema.SignedVoluntaryExit) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Aggregations

Context (io.javalin.http.Context)1 HttpMethod (io.javalin.plugin.openapi.annotations.HttpMethod)1 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)1 OpenApiContent (io.javalin.plugin.openapi.annotations.OpenApiContent)1 OpenApiRequestBody (io.javalin.plugin.openapi.annotations.OpenApiRequestBody)1 OpenApiResponse (io.javalin.plugin.openapi.annotations.OpenApiResponse)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 DataProvider (tech.pegasys.teku.api.DataProvider)1 NodeDataProvider (tech.pegasys.teku.api.NodeDataProvider)1 SignedVoluntaryExit (tech.pegasys.teku.api.schema.SignedVoluntaryExit)1 AbstractHandler (tech.pegasys.teku.beaconrestapi.handlers.AbstractHandler)1 BadRequest (tech.pegasys.teku.beaconrestapi.schema.BadRequest)1 SC_BAD_REQUEST (tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST)1 SC_OK (tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK)1 RES_BAD_REQUEST (tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_BAD_REQUEST)1 RES_INTERNAL_ERROR (tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_INTERNAL_ERROR)1 RES_OK (tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_OK)1 TAG_BEACON (tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON)1 JsonProvider (tech.pegasys.teku.provider.JsonProvider)1