From 14b12f59d1b0891be14b462642934c36f813bd6c Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Fri, 9 Aug 2024 16:13:54 -0400 Subject: [PATCH] fix(app-shell): forward usb request errors and log We were swallowing all errors from usb requests, which doesn't seem like a great idea - it definitely led to lots of errors in browser logs. While we're at it, let's get some more in-detph logging of usb requests. --- app-shell/src/usb.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app-shell/src/usb.ts b/app-shell/src/usb.ts index 276c537f062..8f329c7fa14 100644 --- a/app-shell/src/usb.ts +++ b/app-shell/src/usb.ts @@ -18,7 +18,7 @@ import { } from './constants' import type { IpcMainInvokeEvent } from 'electron' -import type { AxiosRequestConfig } from 'axios' +import type { AxiosRequestConfig, isAxiosError } from 'axios' import type { IPCSafeFormData } from '@opentrons/app/src/redux/shell/types' import type { UsbDevice } from '@opentrons/app/src/redux/system-info/types' import type { PortInfo } from '@opentrons/usb-bridge/node-client' @@ -114,12 +114,14 @@ async function usbListener( const usbHttpAgent = getSerialPortHttpAgent() try { + usbLog.silly(`${config.method} ${config.url} timeout=${config.timeout}`) const response = await axios.request({ httpAgent: usbHttpAgent, ...config, data, headers: { ...config.headers, ...formHeaders }, }) + usbLog.silly(`${config.method} ${config.url} resolved ok`) return { error: false, data: response.data, @@ -127,9 +129,12 @@ async function usbListener( statusText: response.statusText, } } catch (e) { - if (e instanceof Error) { - console.log(`axios request error ${e?.message ?? 'unknown'}`) - } + usbLog.info( + `${config.method} ${config.url} failed: ${ + isAxiosError(e) ? e.toJSON() : JSON.stringify(e) + }` + ) + throw e } }