From 1af3dbdb5ebaa8c283d4b2cb6eecd04aeb1949ba Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Thu, 15 Oct 2020 12:37:50 +0200 Subject: [PATCH] Provide more context. Handle more edge cases. --- plugins/newrelic/src/api/index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/newrelic/src/api/index.ts b/plugins/newrelic/src/api/index.ts index eb94acdbd1..d76a87875c 100644 --- a/plugins/newrelic/src/api/index.ts +++ b/plugins/newrelic/src/api/index.ts @@ -84,10 +84,20 @@ export class NewRelicClient implements NewRelicApi { async getApplications(): Promise { const url = await this.getApiUrl('apm', 'applications.json'); const response = await fetch(url); - const responseJson = await response.json(); + let responseJson; + + try { + responseJson = await response.json(); + } catch (e) { + responseJson = { applications: [] }; + } if (response.status !== 200) { - throw new Error(responseJson?.error?.title || response.statusText); + throw new Error( + `Error communicating with New Relic: ${ + responseJson?.error?.title || response.statusText + }`, + ); } return responseJson;