stac-server
stac-server copied to clipboard
Incorrect error displayed when index failed to create
When creating a new collection, we saw this error when the index for the collection was being created:
DEBUG Error creating index collection_xxx, already created: ResponseError: validation_exception
The index did not already exist, though. When we dug into it further, we found that the actual error from ES was:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Validation Failed: 1: this action would add [10] total shards, but this cluster currently has [2992]/[3000] maximum shards open;"
}
],
"type": "illegal_argument_exception",
"reason": "Validation Failed: 1: this action would add [10] total shards, but this cluster currently has [2992]/[3000] maximum shards open;"
},
"status": 400
}
The issue is here: https://github.com/stac-utils/stac-server/blob/main/src/lib/esClient.js#L66
It is assuming that any exception being thrown is caused by the index already existing. That will not always be the case.
While this is being updated, we should also give a better error message. In this case the error that was displayed was just validation_exception. It would have been more useful to display the value of meta.body.error.reason.