From b43aff0f9f4108d7620a82b5b5c9ceb025b92278 Mon Sep 17 00:00:00 2001 From: John Schulz Date: Mon, 31 Aug 2020 13:27:03 -0400 Subject: [PATCH] Revert prior try/catch. Use res.ok --- .../scripts/dev_agent/script.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/ingest_manager/scripts/dev_agent/script.ts b/x-pack/plugins/ingest_manager/scripts/dev_agent/script.ts index 0b50da1f2ef5e..65375a076e9a4 100644 --- a/x-pack/plugins/ingest_manager/scripts/dev_agent/script.ts +++ b/x-pack/plugins/ingest_manager/scripts/dev_agent/script.ts @@ -111,23 +111,24 @@ async function enroll(kibanaURL: string, apiKey: string, log: ToolingLog): Promi }, }, }; - try { - const res = await fetch(`${kibanaURL}/api/ingest_manager/fleet/agents/enroll`, { - method: 'POST', - body: JSON.stringify(body), - headers: { - 'kbn-xsrf': 'xxx', - Authorization: `ApiKey ${apiKey}`, - 'Content-Type': 'application/json', - }, - }); - const obj: PostAgentEnrollResponse = await res.json(); - return { - id: obj.item.id, - access_api_key: obj.item.access_api_key, - }; - } catch (e) { - log.error(e); + const res = await fetch(`${kibanaURL}/api/ingest_manager/fleet/agents/enroll`, { + method: 'POST', + body: JSON.stringify(body), + headers: { + 'kbn-xsrf': 'xxx', + Authorization: `ApiKey ${apiKey}`, + 'Content-Type': 'application/json', + }, + }); + const obj: PostAgentEnrollResponse = await res.json(); + + if (!res.ok) { + log.error(JSON.stringify(obj, null, 2)); throw new Error('unable to enroll'); } + + return { + id: obj.item.id, + access_api_key: obj.item.access_api_key, + }; }