From 2fe7af0c225faf98eb46614c860ea26a9ca842a6 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 3 Mar 2020 16:44:32 +0700 Subject: [PATCH] Handle some cases of api not returning full data. --- backend/src/api/bitcoin/electrs-api.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/src/api/bitcoin/electrs-api.ts b/backend/src/api/bitcoin/electrs-api.ts index d4100e88b..4927f3f0c 100644 --- a/backend/src/api/bitcoin/electrs-api.ts +++ b/backend/src/api/bitcoin/electrs-api.ts @@ -36,7 +36,11 @@ class ElectrsApi { } else if (res.statusCode !== 200) { reject(response); } else { - resolve(response); + if (response.constructor === Array) { + resolve(response); + } else { + reject('returned invalid data'); + } } }); }); @@ -50,7 +54,11 @@ class ElectrsApi { } else if (res.statusCode !== 200) { reject(response); } else { - resolve(response); + if (response.constructor === Object) { + resolve(response); + } else { + reject('returned invalid data'); + } } }); }); @@ -78,7 +86,11 @@ class ElectrsApi { } else if (res.statusCode !== 200) { reject(response); } else { - resolve(response); + if (response.constructor === Array) { + resolve(response); + } else { + reject('returned invalid data'); + } } }); });