From 2c7f1cb0d453da32776a4ca8b9055165813089ca Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 24 Jan 2024 17:58:37 -0300 Subject: [PATCH] libs: blueos: Add specific error for when the path is not available This can be used to check if the path was not set, and should then be set for the first time. --- src/libs/blueos.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libs/blueos.ts b/src/libs/blueos.ts index f416e8e73..52537489a 100644 --- a/src/libs/blueos.ts +++ b/src/libs/blueos.ts @@ -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 ( @@ -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}`) } }