diff --git a/lib/core/shared/sdk/embeddedSdk.ts b/lib/core/shared/sdk/embeddedSdk.ts index c1532db37f..f99635bf23 100644 --- a/lib/core/shared/sdk/embeddedSdk.ts +++ b/lib/core/shared/sdk/embeddedSdk.ts @@ -149,7 +149,10 @@ export class EmbeddedSDK extends Kuzzle { * @param request - API request (https://docs.kuzzle.io/core/2/guides/main-concepts/1-api#other-protocols) * @param options - Optional arguments */ - query( + query< + TRequest extends BaseRequest = BaseRequest, + TResult extends JSONObject = JSONObject + >( request: TRequest, options: { propagate?: boolean } = {} ): Promise> { diff --git a/lib/kerror/index.ts b/lib/kerror/index.ts index 594cc2a107..47d0ad354c 100644 --- a/lib/kerror/index.ts +++ b/lib/kerror/index.ts @@ -206,7 +206,7 @@ export function rawGetFrom( // If a stacktrace is present, we need to modify the first line because it // still contains the original error message - if (derivedError.stack && derivedError.stack.length) { + if (derivedError.stack && derivedError.stack.length && source.stack) { const stackArray = source.stack.split("\n"); stackArray.shift(); derivedError.stack = [ diff --git a/lib/service/storage/esWrapper.js b/lib/service/storage/esWrapper.js index cd12826560..51ddcb062d 100644 --- a/lib/service/storage/esWrapper.js +++ b/lib/service/storage/esWrapper.js @@ -232,6 +232,10 @@ class ESWrapper { _handleNotFoundError(error, message) { let errorMessage = message; + if (!error.body._index) { + return kerror.get("unexpected_not_found", errorMessage); + } + // _index= "&nyc-open-data.yellow-taxi" const index = error.body._index.split(".")[0].slice(1); const collection = error.body._index.split(".")[1]; diff --git a/package-lock.json b/package-lock.json index 20af7d635c..8ebf67da59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kuzzle", - "version": "2.19.6", + "version": "2.19.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "kuzzle", - "version": "2.19.6", + "version": "2.19.7", "license": "Apache-2.0", "dependencies": { "@elastic/elasticsearch": "https://github.com/elastic/elasticsearch-js/archive/refs/tags/v7.13.0.tar.gz", diff --git a/package.json b/package.json index 684c418c55..90ea0a0dd6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kuzzle", "author": "The Kuzzle Team ", - "version": "2.19.6", + "version": "2.19.7", "description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.", "bin": "bin/start-kuzzle-server", "scripts": { @@ -26,6 +26,7 @@ "test:functional:legacy:mqtt": "npx cucumber-js --format progress-bar --profile mqtt ./features-legacy", "cucumber": "cucumber.js --fail-fast", "codecov": "codecov", + "prettier": "npx prettier ./lib ./test ./bin ./features ./plugins/available/functional-test-plugin --write", "test:lint": "npm run test:lint:js && npm run test:lint:ts", "test:lint:ts": "eslint --max-warnings=0 ./lib --ext .ts --config .eslintc-ts.json", "test:lint:ts:fix": "eslint --max-warnings=0 --fix ./lib --ext .ts --config .eslintc-ts.json", diff --git a/test/service/storage/esWrapper.test.js b/test/service/storage/esWrapper.test.js index ca355a26cd..c4d7ff8c9f 100644 --- a/test/service/storage/esWrapper.test.js +++ b/test/service/storage/esWrapper.test.js @@ -83,6 +83,26 @@ describe("Test: ElasticSearch Wrapper", () => { }); }); + it("should handle unexpected not found", () => { + const error = new Error("test"); + error.meta = { statusCode: 404 }; + error.body = { + found: false, + _id: "mehry", + error: { + reason: "foo", + "resource.id": "bar", + }, + }; + + const formatted = esWrapper.formatESError(error); + + should(formatted).be.match({ + message: "test", + id: "services.storage.unexpected_not_found", + }); + }); + it("should handle unknown DSL keyword", () => { const error = new Error(""); error.meta = {