Error handling in get_es_version()

This commit is contained in:
2022-03-05 14:59:37 -05:00
parent e9f92330fd
commit 2b639bd4ac
3 changed files with 20 additions and 5 deletions

View File

@@ -21,6 +21,8 @@ void free_queue(int max);
void elastic_flush();
void print_error(response_t *r);
void destroy_indexer(es_indexer_t *indexer) {
if (indexer == NULL) {
@@ -413,12 +415,20 @@ es_version_t *elastic_get_version(const char *es_url) {
*(tmp + r->size) = '\0';
cJSON *response = cJSON_Parse(tmp);
free(tmp);
free_response(r);
if (response == NULL) {
return NULL;
}
if (cJSON_GetObjectItem(response, "error") != NULL) {
LOG_WARNING("elastic.c", "Could not get Elasticsearch version")
print_error(r);
free_response(r);
return NULL;
}
free_response(r);
if (cJSON_GetObjectItem(response, "version") == NULL ||
cJSON_GetObjectItem(cJSON_GetObjectItem(response, "version"), "number") == NULL) {
cJSON_Delete(response);