From c9d699c663f7e59062e274a1e47d22669b2460a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Thu, 21 Jun 2018 11:20:23 +0200 Subject: [PATCH] fix network usage --- src/helpers/devices/getOsuFirmware.js | 21 +++++++++----------- src/helpers/firmware/getFinalFirmwareById.js | 13 +++--------- src/helpers/firmware/installFinalFirmware.js | 4 +--- src/helpers/firmware/installMcu.js | 1 - src/helpers/firmware/installOsuFirmware.js | 4 +--- 5 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/helpers/devices/getOsuFirmware.js b/src/helpers/devices/getOsuFirmware.js index 8ee45576..eaf8344f 100644 --- a/src/helpers/devices/getOsuFirmware.js +++ b/src/helpers/devices/getOsuFirmware.js @@ -1,5 +1,5 @@ // @flow -import axios from 'axios' +import network from 'api/network' import { GET_CURRENT_OSU } from 'helpers/urls' @@ -8,19 +8,16 @@ type Input = { deviceId: string | number, } -let error export default async (input: Input): Promise<*> => { - try { - const provider = 1 - const { data } = await axios.post(GET_CURRENT_OSU, { + const provider = 1 + const { data } = await network({ + method: 'POST', + url: GET_CURRENT_OSU, + data: { device_version: input.deviceId, version_name: input.version, provider, - }) - return data - } catch (err) { - error = Error(err.message) - error.stack = err.stack - throw error - } + }, + }) + return data } diff --git a/src/helpers/firmware/getFinalFirmwareById.js b/src/helpers/firmware/getFinalFirmwareById.js index ec73461f..d3296a9c 100644 --- a/src/helpers/firmware/getFinalFirmwareById.js +++ b/src/helpers/firmware/getFinalFirmwareById.js @@ -1,15 +1,8 @@ // @flow -import axios from 'axios' - +import network from 'api/network' import { GET_FINAL_FIRMWARE } from 'helpers/urls' export default async (id: number) => { - try { - const { data } = await axios.get(`${GET_FINAL_FIRMWARE}/${id}`) - return data - } catch (err) { - const error = Error(err.message) - error.stack = err.stack - throw err - } + const { data } = await network({ method: 'GET', url: `${GET_FINAL_FIRMWARE}/${id}` }) + return data } diff --git a/src/helpers/firmware/installFinalFirmware.js b/src/helpers/firmware/installFinalFirmware.js index 365a37d6..f2c3c885 100644 --- a/src/helpers/firmware/installFinalFirmware.js +++ b/src/helpers/firmware/installFinalFirmware.js @@ -30,9 +30,7 @@ export default async (transport: Transport<*>, app: Input): Result => { const url = WS_INSTALL(params) await createDeviceSocket(transport, url).toPromise() return { success: true } - } catch (err) { - const error = Error(err.message) - error.stack = err.stack + } catch (error) { const result = { success: false, error } throw result } diff --git a/src/helpers/firmware/installMcu.js b/src/helpers/firmware/installMcu.js index 0c0ceb62..44ae9c37 100644 --- a/src/helpers/firmware/installMcu.js +++ b/src/helpers/firmware/installMcu.js @@ -13,7 +13,6 @@ export default async ( ): Result => { const { version } = args const nextVersion = await getNextMCU(version) - const params = { targetId: args.targetId, version: nextVersion.name, diff --git a/src/helpers/firmware/installOsuFirmware.js b/src/helpers/firmware/installOsuFirmware.js index 5c8b95ff..5995b7ae 100644 --- a/src/helpers/firmware/installOsuFirmware.js +++ b/src/helpers/firmware/installOsuFirmware.js @@ -22,9 +22,7 @@ export default async ( const url = WS_INSTALL(params) await createDeviceSocket(transport, url).toPromise() return { success: true } - } catch (err) { - const error = Error(err.message) - error.stack = err.stack + } catch (error) { const result = { success: false, error } throw result }