Browse Source
Merge pull request #886 from gre/include-url-and-method-in-http-error
Include URL and method for debuggability
master
Gaëtan Renaudeau
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
11 additions and
2 deletions
-
src/api/network.js
|
|
@ -4,6 +4,7 @@ import { GET_CALLS_RETRY, GET_CALLS_TIMEOUT } from 'config/constants' |
|
|
|
import { retry } from 'helpers/promise' |
|
|
|
import logger from 'logger' |
|
|
|
import { createCustomErrorClass } from 'helpers/errors' |
|
|
|
import anonymizer from 'helpers/anonymizer' |
|
|
|
|
|
|
|
export const LedgerAPIErrorWithMessage = createCustomErrorClass('LedgerAPIErrorWithMessage') |
|
|
|
export const LedgerAPIError = createCustomErrorClass('LedgerAPIError') |
|
|
@ -34,12 +35,20 @@ const userFriendlyError = <A>(p: Promise<A>, { url, method, startTime }): Promis |
|
|
|
logger.warn("can't parse server result", e) |
|
|
|
} |
|
|
|
if (msg && msg[0] !== '<') { |
|
|
|
errorToThrow = new LedgerAPIErrorWithMessage(msg) |
|
|
|
errorToThrow = new LedgerAPIErrorWithMessage(msg, { |
|
|
|
status, |
|
|
|
url: anonymizer.url(url), |
|
|
|
method, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!errorToThrow) { |
|
|
|
errorToThrow = new LedgerAPIError(`LedgerAPIError ${status}`, { status }) |
|
|
|
errorToThrow = new LedgerAPIError(`LedgerAPIError ${status}`, { |
|
|
|
status, |
|
|
|
url: anonymizer.url(url), |
|
|
|
method, |
|
|
|
}) |
|
|
|
} |
|
|
|
logger.networkError({ |
|
|
|
status, |
|
|
|