Browse Source

Fix error imprecision in all Manager calls

the code is equivalent except errors thrown don't get decorated back into an 'Error' leading to imprecision
we'll need to double check all is fine but this will *make errors great again*.
this is really an antipattern we have to avoid.
master
Gaëtan Renaudeau 7 years ago
parent
commit
8f9207542d
  1. 6
      src/helpers/apps/listAppVersions.js
  2. 6
      src/helpers/apps/listApps.js
  3. 6
      src/helpers/apps/listCategories.js
  4. 6
      src/helpers/common.js
  5. 7
      src/helpers/devices/getCurrentFirmware.js
  6. 6
      src/helpers/devices/getLatestFirmwareForDevice.js
  7. 6
      src/helpers/devices/isDashboardOpen.js
  8. 6
      src/helpers/devices/shouldFlashMcu.js
  9. 6
      src/helpers/firmware/getMcus.js
  10. 6
      src/helpers/firmware/getNextMCU.js
  11. 2
      src/helpers/urls.js

6
src/helpers/apps/listAppVersions.js

@ -7,7 +7,6 @@ import getDeviceVersion from 'helpers/devices/getDeviceVersion'
import getCurrentFirmware from 'helpers/devices/getCurrentFirmware'
export default async (deviceInfo: DeviceInfo) => {
try {
const deviceData = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
const firmwareData = await getCurrentFirmware({
deviceId: deviceData.id,
@ -23,9 +22,4 @@ export default async (deviceInfo: DeviceInfo) => {
data: { application_versions },
} = await network({ method: 'POST', url: APPLICATIONS_BY_DEVICE, data: params })
return application_versions.length > 0 ? application_versions : []
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
}

6
src/helpers/apps/listApps.js

@ -4,12 +4,6 @@ import network from 'api/network'
import { GET_APPLICATIONS } from 'helpers/urls'
export default async () => {
try {
const { data } = await network({ method: 'GET', url: GET_APPLICATIONS })
return data.length > 0 ? data : []
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
}

6
src/helpers/apps/listCategories.js

@ -4,12 +4,6 @@ import network from 'api/network'
import { GET_CATEGORIES } from 'helpers/urls'
export default async () => {
try {
const { data } = await network({ method: 'GET', url: GET_CATEGORIES })
return data.length > 0 ? data : []
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
}

6
src/helpers/common.js

@ -27,7 +27,6 @@ export type LedgerScriptParams = {
* Retrieve targetId and firmware version from device
*/
export async function getFirmwareInfo(transport: Transport<*>) {
try {
const res = await transport.send(...APDUS.GET_FIRMWARE)
const byteArray = [...res]
const data = byteArray.slice(0, byteArray.length - 2)
@ -62,9 +61,4 @@ export async function getFirmwareInfo(transport: Transport<*>) {
}
return { targetId, seVersion, flags, mcuVersion }
} catch (err) {
const error = new Error(err.message)
error.stack = err.stack
throw error
}
}

7
src/helpers/devices/getCurrentFirmware.js

@ -9,9 +9,7 @@ type Input = {
provider: number,
}
let error
export default async (input: Input): Promise<*> => {
try {
const { data } = await network({
method: 'POST',
url: GET_CURRENT_FIRMWARE,
@ -22,9 +20,4 @@ export default async (input: Input): Promise<*> => {
},
})
return data
} catch (err) {
error = Error(err.message)
error.stack = err.stack
throw error
}
}

6
src/helpers/devices/getLatestFirmwareForDevice.js

@ -10,7 +10,6 @@ import getCurrentFirmware from './getCurrentFirmware'
import getDeviceVersion from './getDeviceVersion'
export default async (deviceInfo: DeviceInfo) => {
try {
// Get device infos from targetId
const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
@ -54,9 +53,4 @@ export default async (deviceInfo: DeviceInfo) => {
}
return { ...se_firmware_osu_version, shouldFlashMcu: false }
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw error
}
}

6
src/helpers/devices/isDashboardOpen.js

@ -7,16 +7,10 @@ import { getFirmwareInfo } from 'helpers/common'
type Result = boolean
export default async (transport: Transport<*>): Promise<Result> => {
try {
const { targetId, seVersion } = await getFirmwareInfo(transport)
if (targetId && seVersion) {
return true
}
return false
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw error
}
}

6
src/helpers/devices/shouldFlashMcu.js

@ -10,7 +10,6 @@ import getOsuFirmware from './getOsuFirmware'
import getDeviceVersion from './getDeviceVersion'
export default async (deviceInfo: DeviceInfo): Promise<boolean> => {
try {
// Get device infos from targetId
const deviceVersion = await getDeviceVersion(deviceInfo.targetId, deviceInfo.providerId)
@ -47,9 +46,4 @@ export default async (deviceInfo: DeviceInfo): Promise<boolean> => {
.map(mcu => mcu.id)
return !seFirmwareFinalVersion.mcu_versions.includes(...currentMcuVersionId)
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw error
}
}

6
src/helpers/firmware/getMcus.js

@ -4,16 +4,10 @@ import network from 'api/network'
import { GET_MCUS } from 'helpers/urls'
export default async (): Promise<*> => {
try {
const { data } = await network({
method: 'GET',
url: GET_MCUS,
})
return data
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
}

6
src/helpers/firmware/getNextMCU.js

@ -7,7 +7,6 @@ import { createCustomErrorClass } from 'helpers/errors'
const LatestMCUInstalledError = createCustomErrorClass('LatestMCUInstalledError')
export default async (bootloaderVersion: string): Promise<*> => {
try {
const { data } = await network({
method: 'POST',
url: GET_NEXT_MCU,
@ -22,9 +21,4 @@ export default async (bootloaderVersion: string): Promise<*> => {
throw new LatestMCUInstalledError('there is no next mcu version to install')
}
return data
} catch (err) {
const error = Error(err.message)
error.stack = err.stack
throw err
}
}

2
src/helpers/urls.js

@ -14,6 +14,8 @@ const wsURLBuilder = (endpoint: string) => (params?: Object) =>
// const wsURLBuilderProxy = (endpoint: string) => (params?: Object) =>
// `ws://manager.ledger.fr:3501/${endpoint}${params ? `?${qs.stringify(params)}` : ''}`
// FIXME we shouldn't do this here. we should just collocate these where it's used.
export const GET_FINAL_FIRMWARE: string = managerUrlbuilder('firmware_final_versions')
export const GET_DEVICE_VERSION: string = managerUrlbuilder('get_device_version')
export const APPLICATIONS_BY_DEVICE: string = managerUrlbuilder('get_apps')

Loading…
Cancel
Save