From 8f64a44e54ca3baf84378c17b63b4ab3cd658cd2 Mon Sep 17 00:00:00 2001 From: Dominik Broj Date: Mon, 17 Jun 2024 09:47:56 +0200 Subject: [PATCH] Fix "Cannot read ... of undefined" from Axios response (#4541) # What this PR does Fix "Cannot read ... of undefined" from Axios response ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes. --- grafana-plugin/src/utils/faro.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/grafana-plugin/src/utils/faro.ts b/grafana-plugin/src/utils/faro.ts index c9212e95..782511aa 100644 --- a/grafana-plugin/src/utils/faro.ts +++ b/grafana-plugin/src/utils/faro.ts @@ -105,19 +105,19 @@ class BaseFaroHelper { this.faro?.api.pushEvent(name, { url: res?.config?.url, status: `${res?.status}`, - statusText: `${res.statusText}`, - method: res.config?.method.toUpperCase(), + statusText: `${res?.statusText}`, + method: res?.config?.method.toUpperCase(), }); }; - pushAxiosNetworkError = (res: AxiosResponse) => { - this.faro?.api.pushError(new Error(`Network error: ${res.status}`), { + pushAxiosNetworkError = (res?: AxiosResponse) => { + this.faro?.api.pushError(new Error(`Network error: ${res?.status}`), { context: { - url: res.config?.url, + url: res?.config?.url, type: 'network', data: `${safeJSONStringify(res.data)}`, - status: `${res.status}`, - statusText: `${res.statusText}`, + status: `${res?.status}`, + statusText: `${res?.statusText}`, timestamp: new Date().toUTCString(), }, });