diff --git a/src/api/Ledger.js b/src/api/Ledger.js
index 722a90a8..2c84ab5d 100644
--- a/src/api/Ledger.js
+++ b/src/api/Ledger.js
@@ -1,48 +1,7 @@
// @flow
import type { Currency } from '@ledgerhq/live-common/lib/types'
-import logger from 'logger'
-import createCustomErrorClass from 'helpers/createCustomErrorClass'
const BASE_URL = process.env.LEDGER_REST_API_BASE || 'https://api.ledgerwallet.com/'
-export const LedgerAPIErrorWithMessage = createCustomErrorClass('LedgerAPIErrorWithMessage')
-export const LedgerAPIError = createCustomErrorClass('LedgerAPIError')
-export const NetworkDown = createCustomErrorClass('NetworkDown')
-
-export const userFriendlyError = (p: Promise): Promise =>
- p.catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code
- // that falls out of the range of 2xx
- const { data } = error.response
- if (data && typeof data.error === 'string') {
- let msg = data.error || data.message
- if (typeof msg === 'string') {
- const m = msg.match(/^JsDefined\((.*)\)$/)
- if (m) {
- try {
- const { message } = JSON.parse(m[1])
- if (typeof message === 'string') {
- msg = message
- }
- } catch (e) {
- logger.warn("can't parse server result", e)
- }
- }
- throw new LedgerAPIErrorWithMessage(msg)
- }
- }
- const { status } = error.response
- logger.log('Ledger API: HTTP status', status, 'data: ', error.response.data)
- throw new LedgerAPIError(`LedgerAPIError ${status}`, { status })
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- throw new NetworkDown()
- }
- throw error
- })
-
export const blockchainBaseURL = ({ ledgerExplorerId }: Currency): ?string =>
ledgerExplorerId ? `${BASE_URL}blockchain/v2/${ledgerExplorerId}` : null
diff --git a/src/api/network.js b/src/api/network.js
index 091f5fe4..b4bfb76d 100644
--- a/src/api/network.js
+++ b/src/api/network.js
@@ -1,8 +1,50 @@
// @flow
import axios from 'axios'
import { GET_CALLS_RETRY, GET_CALLS_TIMEOUT } from 'config/constants'
-import { userFriendlyError } from 'api/Ledger'
import { retry } from 'helpers/promise'
+import logger from 'logger'
+import createCustomErrorClass from 'helpers/createCustomErrorClass'
+
+export const LedgerAPIErrorWithMessage = createCustomErrorClass('LedgerAPIErrorWithMessage')
+export const LedgerAPIError = createCustomErrorClass('LedgerAPIError')
+export const NetworkDown = createCustomErrorClass('NetworkDown')
+
+const userFriendlyError = (p: Promise): Promise =>
+ p.catch(error => {
+ if (error.response) {
+ // The request was made and the server responded with a status code
+ // that falls out of the range of 2xx
+ const { data } = error.response
+ if (data && typeof data.error === 'string') {
+ let msg = data.error || data.message
+ if (typeof msg === 'string') {
+ const m = msg.match(/^JsDefined\((.*)\)$/)
+ if (m) {
+ try {
+ const { message } = JSON.parse(m[1])
+ if (typeof message === 'string') {
+ msg = message
+ }
+ } catch (e) {
+ logger.warn("can't parse server result", e)
+ }
+ }
+ if (msg && msg[0] !== '<') {
+ throw new LedgerAPIErrorWithMessage(msg)
+ }
+ }
+ }
+ const { status } = error.response
+ logger.log('Ledger API: HTTP status', status, 'data: ', error.response.data)
+ throw new LedgerAPIError(`LedgerAPIError ${status}`, { status })
+ } else if (error.request) {
+ // The request was made but no response was received
+ // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
+ // http.ClientRequest in node.js
+ throw new NetworkDown()
+ }
+ throw error
+ })
let implementation = (arg: Object) => {
let promise