<commit_before>package org.elasticsearch.plugin.swagger.v1_2.rest;

import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.description.MainApiMetadataProvider;
import org.elasticsearch.description.ElasticSearchMetadataProvider;
import org.elasticsearch.rest.*;
import org.elasticsearch.plugin.swagger.v1_2.model.SwaggerModel;

import static org.elasticsearch.rest.RestStatus.OK;

public abstract class RequestHandler extends BaseRestHandler {

    protected RequestHandler(Settings settings, RestController controller, Client client) {
        super(settings, controller, client);
    }

    protected abstract SwaggerModel handleRequest(RestRequest request, Client client) throws Exception;

    @Override
    protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
        SwaggerModel model = handleRequest(request, client);
        RestResponse response = new BytesRestResponse(OK, "application/json", model.toJson());

        response.addHeader("Access-Control-Allow-Methods", "GET");

        channel.sendResponse(response);
    }
    
    protected ElasticSearchMetadataProvider getMetadataProvider(RestRequest request, Client client) {
        return new MainApiMetadataProvider(client, request.param("indexOrAlias"));
    }
}<commit_msg>Log exceptions<commit_after>package org.elasticsearch.plugin.swagger.v1_2.rest;

import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.description.MainApiMetadataProvider;
import org.elasticsearch.description.ElasticSearchMetadataProvider;
import org.elasticsearch.rest.*;
import org.elasticsearch.plugin.swagger.v1_2.model.SwaggerModel;

import static org.elasticsearch.rest.RestStatus.OK;

public abstract class RequestHandler extends BaseRestHandler {

    protected RequestHandler(Settings settings, RestController controller, Client client) {
        super(settings, controller, client);
    }

    protected abstract SwaggerModel handleRequest(RestRequest request, Client client) throws Exception;

    @Override
    protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
        try {
            SwaggerModel model = handleRequest(request, client);
            RestResponse response = new BytesRestResponse(OK, "application/json", model.toJson());

            response.addHeader("Access-Control-Allow-Methods", "GET");

            channel.sendResponse(response);
        }
        catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            throw ex;
        }
    }
    
    protected ElasticSearchMetadataProvider getMetadataProvider(RestRequest request, Client client) {
        return new MainApiMetadataProvider(client, request.param("indexOrAlias"));
    }
}
{'fraction_non_alphanumeric': 0.08481675392670157, 'fraction_numerical': 0.002792321116928447, 'mean_word_length': 4.490421455938697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6891900', 'n_tokens_mistral': 689, 'n_tokens_neox': 694, 'n_words': 161}