From 469a7e2400afbae951316c801b8f829aae949990 Mon Sep 17 00:00:00 2001 From: Kevin Campion Date: Fri, 29 Dec 2017 06:04:13 +0100 Subject: [PATCH] Update the error manager To prevent "UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: response.error.filter is not a function" when the error is "Error: EFunding:No funding method" --- kraken.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/kraken.js b/kraken.js index 4cedb7f..7685156 100644 --- a/kraken.js +++ b/kraken.js @@ -43,15 +43,20 @@ const rawRequest = async (url, headers, data, timeout) => { const response = JSON.parse(body); if(response.error && response.error.length) { - const error = response.error - .filter((e) => e.startsWith('E')) + const error = response.error; + if(typeof error === 'object') { + error.filter((e) => e.startsWith('E')) .map((e) => e.substr(1)); - if(!error.length) { - throw new Error("Kraken API returned an unknown error"); - } + if(!error.length) { + throw new Error("Kraken API returned an unknown error"); + } - throw new Error(error.join(', ')); + throw new Error(error.join(', ')); + } + else { + throw new Error(error); + } } return response;