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 Jun 14, 2024
1 parent 1d0c1d9 commit b1d5edc
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'

const defaultTimeout = 10000

Expand All @@ -11,7 +13,15 @@ export const getBagOfHoldingFromVehicle = async (
const options = { timeout: defaultTimeout, retry: 0 }
return await ky.get(`http://${vehicleAddress}/bag/v1.0/get/${bagPath}`, options).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 b1d5edc

Please sign in to comment.