Skip to content

Commit

Permalink
fix(app-shell): forward usb request errors and log
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sfoster1 committed Aug 9, 2024
1 parent 42db1ee commit 14b12f5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app-shell/src/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from './constants'

import type { IpcMainInvokeEvent } from 'electron'
import type { AxiosRequestConfig } from 'axios'
import type { AxiosRequestConfig, isAxiosError } from 'axios'

Check failure on line 21 in app-shell/src/usb.ts

View workflow job for this annotation

GitHub Actions / js checks

'"axios"' has no exported member named 'isAxiosError'. Did you mean 'AxiosError'?

Check failure on line 21 in app-shell/src/usb.ts

View workflow job for this annotation

GitHub Actions / js checks

Type import "isAxiosError" is used by decorator metadata

Check failure on line 21 in app-shell/src/usb.ts

View workflow job for this annotation

GitHub Actions / js checks

'"axios"' has no exported member named 'isAxiosError'. Did you mean 'AxiosError'?

Check failure on line 21 in app-shell/src/usb.ts

View workflow job for this annotation

GitHub Actions / js checks

Type import "isAxiosError" is used by decorator metadata
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'
Expand Down Expand Up @@ -114,22 +114,27 @@ 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,
status: response.status,
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)

Check failure on line 134 in app-shell/src/usb.ts

View workflow job for this annotation

GitHub Actions / js checks

'isAxiosError' cannot be used as a value because it was imported using 'import type'.

Check failure on line 134 in app-shell/src/usb.ts

View workflow job for this annotation

GitHub Actions / js checks

'e' is of type 'unknown'.

Check failure on line 134 in app-shell/src/usb.ts

View workflow job for this annotation

GitHub Actions / js checks

'isAxiosError' cannot be used as a value because it was imported using 'import type'.

Check failure on line 134 in app-shell/src/usb.ts

View workflow job for this annotation

GitHub Actions / js checks

'e' is of type 'unknown'.
}`
)
throw e
}
}

Expand Down

0 comments on commit 14b12f5

Please sign in to comment.