Skip to content

Commit

Permalink
blueos: Throw if JSON response is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Feb 17, 2025
1 parent d46059c commit eed892a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libs/blueos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export const getBagOfHoldingFromVehicle = async (
): Promise<Record<string, any> | any> => {
try {
const options = { timeout: defaultTimeout, retry: 0 }
return await ky.get(`http://${vehicleAddress}/bag/v1.0/get/${bagPath}`, options).json()
const res = await ky.get(`http://${vehicleAddress}/bag/v1.0/get/${bagPath}`, options)
if (res === undefined || !res.ok) {
throw new Error(`Could not get bag of holdings for ${bagPath}. ${res?.statusText}`)
}
return await res.json()
} catch (error) {
const errorBody = await (error as HTTPError).response.json()
if (errorBody.detail === 'Invalid path') {
Expand Down

0 comments on commit eed892a

Please sign in to comment.