Skip to content

Commit

Permalink
libs: blueos: Add specific error for when the path is not available
Browse files Browse the repository at this point in the history
This can be used to check if the path was not set, and should then be set for the first time.
  • Loading branch information
rafaellehmkuhl committed Feb 1, 2024
1 parent f222fb4 commit 4d69264
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/libs/blueos.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ky from 'ky'
import ky, { HTTPError } from 'ky'

export const NoPathInBlueOsErrorName = 'NoPathInBlueOS'

/* eslint-disable @typescript-eslint/no-explicit-any */
export const getBagOfHoldingFromVehicle = async (
Expand All @@ -8,7 +10,15 @@ export const getBagOfHoldingFromVehicle = async (
try {
return await ky.get(`http://${vehicleAddress}/bag/v1.0/get/${bagPath}`, { timeout: 5000, retry: 0 }).json()
} catch (error) {
throw new Error(`Could not get bag of holdings for ${bagName}. ${error}`)
const errorBody = await (error as HTTPError).response.json()
console.log(errorBody)
if (errorBody.detail === 'Invalid path') {
const noPathError = new Error(`No data available in BlueOS storage for path '${bagPath}'.`)
noPathError.name = NoPathInBlueOsErrorName
console.log(noPathError)
throw noPathError
}
throw new Error(`Could not get bag of holdings for ${bagPath}. ${error}`)
}
}

Expand Down

0 comments on commit 4d69264

Please sign in to comment.