Skip to content

Commit

Permalink
Revert prior try/catch. Use res.ok
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Aug 31, 2020
1 parent 58727a5 commit b43aff0
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions x-pack/plugins/ingest_manager/scripts/dev_agent/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

0 comments on commit b43aff0

Please sign in to comment.