From dd6613f837238564dea7e92445999c0a0264db87 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Mon, 13 Aug 2018 14:36:37 -0700 Subject: [PATCH 1/3] Place back saved object client error formatting --- src/ui/public/saved_objects/saved_objects_client.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ui/public/saved_objects/saved_objects_client.js b/src/ui/public/saved_objects/saved_objects_client.js index e762f678e634e..b48e13342bc80 100644 --- a/src/ui/public/saved_objects/saved_objects_client.js +++ b/src/ui/public/saved_objects/saved_objects_client.js @@ -232,6 +232,16 @@ export class SavedObjectsClient { return Promise.reject(new Error('body not permitted for GET requests')); } - return kfetch({ method, pathname: path, query, body: JSON.stringify(body) }); + return kfetch({ method, pathname: path, query, body: JSON.stringify(body) }) + .catch(resp => { + const respBody = resp.body; + const respRes = resp.res; + const err = new Error(respBody.message || respBody.error || `${respRes} Response`); + + err.statusCode = respBody.statusCode || respRes.status; + err.body = respBody; + + throw err; + }); } } From a12a56838d8dc52b037a2d1577e1ebc902a9738a Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Mon, 13 Aug 2018 15:04:34 -0700 Subject: [PATCH 2/3] Rename vars --- src/ui/public/saved_objects/saved_objects_client.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ui/public/saved_objects/saved_objects_client.js b/src/ui/public/saved_objects/saved_objects_client.js index b48e13342bc80..e8679eded264b 100644 --- a/src/ui/public/saved_objects/saved_objects_client.js +++ b/src/ui/public/saved_objects/saved_objects_client.js @@ -233,13 +233,13 @@ export class SavedObjectsClient { } return kfetch({ method, pathname: path, query, body: JSON.stringify(body) }) - .catch(resp => { - const respBody = resp.body; - const respRes = resp.res; - const err = new Error(respBody.message || respBody.error || `${respRes} Response`); + .catch(fetchError => { + const errorBody = fetchError.body; + const errorRes = fetchError.res; + const err = new Error(errorBody.message || errorBody.error || `${errorRes} Response`); - err.statusCode = respBody.statusCode || respRes.status; - err.body = respBody; + err.statusCode = errorBody.statusCode || errorRes.status; + err.errorBody = errorBody; throw err; }); From 2eaaa5b7105361c903515fcc53bda3dfc383fc32 Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Mon, 13 Aug 2018 15:49:05 -0700 Subject: [PATCH 3/3] Change index pattern saving to read FetchError nested status code --- .../index_patterns/__tests__/_index_pattern.test.js | 6 ++++-- src/ui/public/index_patterns/_index_pattern.js | 2 +- src/ui/public/saved_objects/saved_objects_client.js | 12 +----------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/ui/public/index_patterns/__tests__/_index_pattern.test.js b/src/ui/public/index_patterns/__tests__/_index_pattern.test.js index aefbda67e903d..5cfea76c4457a 100644 --- a/src/ui/public/index_patterns/__tests__/_index_pattern.test.js +++ b/src/ui/public/index_patterns/__tests__/_index_pattern.test.js @@ -99,7 +99,9 @@ jest.mock('../../saved_objects', () => { update: async (type, id, body, { version }) => { if (object._version !== version) { throw { - statusCode: 409 + res: { + status: 409 + } }; } @@ -158,6 +160,6 @@ describe('IndexPattern', () => { result = err; } - expect(result.statusCode).toBe(409); + expect(result.res.status).toBe(409); }); }); diff --git a/src/ui/public/index_patterns/_index_pattern.js b/src/ui/public/index_patterns/_index_pattern.js index f2f486d297329..f73952a3e845b 100644 --- a/src/ui/public/index_patterns/_index_pattern.js +++ b/src/ui/public/index_patterns/_index_pattern.js @@ -463,7 +463,7 @@ export function IndexPatternProvider(Private, config, Promise, confirmModalPromi setVersion(this, _version); }) .catch(err => { - if (err.statusCode === 409 && saveAttempts++ < MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS) { + if (_.get(err, 'res.status') === 409 && saveAttempts++ < MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS) { const samePattern = new IndexPattern(this.id); return samePattern.init() .then(() => { diff --git a/src/ui/public/saved_objects/saved_objects_client.js b/src/ui/public/saved_objects/saved_objects_client.js index e8679eded264b..e762f678e634e 100644 --- a/src/ui/public/saved_objects/saved_objects_client.js +++ b/src/ui/public/saved_objects/saved_objects_client.js @@ -232,16 +232,6 @@ export class SavedObjectsClient { return Promise.reject(new Error('body not permitted for GET requests')); } - return kfetch({ method, pathname: path, query, body: JSON.stringify(body) }) - .catch(fetchError => { - const errorBody = fetchError.body; - const errorRes = fetchError.res; - const err = new Error(errorBody.message || errorBody.error || `${errorRes} Response`); - - err.statusCode = errorBody.statusCode || errorRes.status; - err.errorBody = errorBody; - - throw err; - }); + return kfetch({ method, pathname: path, query, body: JSON.stringify(body) }); } }