use of org.apache.ignite.internal.rest.api.ErrorResult in project ignite-3 by apache.
the class ConfigurationHttpHandlers method handleUpdate.
/**
* Handle a configuration update request as json.
*
* @param req Rest request.
* @param res Rest response.
* @param presentation Configuration presentation.
*/
private static CompletableFuture<RestApiHttpResponse> handleUpdate(RestApiHttpRequest req, RestApiHttpResponse res, ConfigurationPresentation<String> presentation) {
String updateReq = req.request().content().toString(StandardCharsets.UTF_8);
return presentation.update(updateReq).thenApply(v -> res).exceptionally(e -> {
if (e instanceof CompletionException) {
e = e.getCause();
}
ErrorResult errRes;
if (e instanceof IllegalArgumentException) {
errRes = new ErrorResult("INVALID_CONFIG_FORMAT", e.getMessage());
} else if (e instanceof ConfigurationValidationException) {
errRes = new ErrorResult("VALIDATION_EXCEPTION", e.getMessage());
} else if (e instanceof IgniteException) {
errRes = new ErrorResult("APPLICATION_EXCEPTION", e.getMessage());
} else {
throw new CompletionException(e);
}
res.status(BAD_REQUEST);
res.json(Map.of("error", errRes));
return res;
});
}
use of org.apache.ignite.internal.rest.api.ErrorResult in project ignite-3 by apache.
the class ConfigurationHttpHandlers method handleRepresentByPath.
/**
* Handle a request to get the configuration by {@link #PATH_PARAM path}.
*
* @param req Rest request.
* @param res Rest response.
* @param presentation Configuration presentation.
*/
private static CompletableFuture<RestApiHttpResponse> handleRepresentByPath(RestApiHttpRequest req, RestApiHttpResponse res, ConfigurationPresentation<String> presentation) {
try {
String cfgPath = req.queryParams().get(PATH_PARAM);
res.json(presentation.representByPath(cfgPath));
} catch (IllegalArgumentException pathE) {
ErrorResult errRes = new ErrorResult("CONFIG_PATH_UNRECOGNIZED", pathE.getMessage());
res.status(BAD_REQUEST);
res.json(Map.of("error", errRes));
}
return CompletableFuture.completedFuture(res);
}
Aggregations