From 87ca75e569d14f5489990044d2479a6f04192ab1 Mon Sep 17 00:00:00 2001 From: restrry Date: Mon, 27 Jul 2020 10:00:29 +0200 Subject: [PATCH 1/3] add note about error format and FTR service --- src/core/MIGRATION_EXAMPLES.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/MIGRATION_EXAMPLES.md b/src/core/MIGRATION_EXAMPLES.md index d630fec652a37..bdc8f125df5c5 100644 --- a/src/core/MIGRATION_EXAMPLES.md +++ b/src/core/MIGRATION_EXAMPLES.md @@ -1082,7 +1082,7 @@ const { body } = await client.asInternalUser.get({ id: 'id' }); const { body } = await client.asInternalUser.get({ id: 'id' }); ``` -- the returned error types changed +- the returned error types changed There are no longer specific errors for every HTTP status code (such as `BadRequest` or `NotFound`). A generic `ResponseError` with the specific `statusCode` is thrown instead. @@ -1097,6 +1097,7 @@ try { if(e instanceof errors.NotFound) { // do something } + if(e.status === 401) {} } ``` @@ -1115,6 +1116,7 @@ try { if(e.name === 'ResponseError' && e.statusCode === 404) { // do something } + if(e.statusCode === 401) {...} } ``` @@ -1178,6 +1180,17 @@ const request = client.asCurrentUser.ping({}, { }); ``` +- Functional tests are subject to migration to the new client as well. +before: +```ts +const client = getService('legacyEs'); +``` + +after: +```ts +const client = getService('es'); +``` + Please refer to the [Breaking changes list](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/breaking-changes.html) for more information about the changes between the legacy and new client. From 8c6ca9775813fe09c1a473ed6b7f04701b21c610 Mon Sep 17 00:00:00 2001 From: restrry Date: Tue, 28 Jul 2020 19:40:43 +0200 Subject: [PATCH 2/3] add notice about lack of response typings --- src/core/MIGRATION_EXAMPLES.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/core/MIGRATION_EXAMPLES.md b/src/core/MIGRATION_EXAMPLES.md index bdc8f125df5c5..8805ae58636c8 100644 --- a/src/core/MIGRATION_EXAMPLES.md +++ b/src/core/MIGRATION_EXAMPLES.md @@ -1180,6 +1180,17 @@ const request = client.asCurrentUser.ping({}, { }); ``` +- the new client doesn't provide exhaustive typings for the response object yet. You might have to copy +response type definitions from the Legacy Elasticsearch library until https://github.com/elastic/elasticsearch-js/pull/970 merged. + +```ts +// platform provides a few typings for internal purposes +import { SearchResponse } from 'src/core/server'; +const { body } = await client.search>(...) +interface Info {...} +const { body } = await client.info(...) +``` + - Functional tests are subject to migration to the new client as well. before: ```ts From fd0599d9967a7f42c0e30490c5760b32958b627e Mon Sep 17 00:00:00 2001 From: restrry Date: Thu, 30 Jul 2020 11:21:04 +0200 Subject: [PATCH 3/3] more detailes example of search response type usage --- src/core/MIGRATION_EXAMPLES.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/MIGRATION_EXAMPLES.md b/src/core/MIGRATION_EXAMPLES.md index 8805ae58636c8..3f34742e44861 100644 --- a/src/core/MIGRATION_EXAMPLES.md +++ b/src/core/MIGRATION_EXAMPLES.md @@ -1186,9 +1186,11 @@ response type definitions from the Legacy Elasticsearch library until https://gi ```ts // platform provides a few typings for internal purposes import { SearchResponse } from 'src/core/server'; -const { body } = await client.search>(...) +type SearchSource = {...}; +type SearchBody = SearchResponse; +const { body } = await client.search(...); interface Info {...} -const { body } = await client.info(...) +const { body } = await client.info(...); ``` - Functional tests are subject to migration to the new client as well.