From b871a39fd46930871c6695a4f9e7aa66b886f617 Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Tue, 7 Jul 2020 10:33:14 +0300 Subject: [PATCH] fix: Rest client error handling --- packages/daf-rest/src/client.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/daf-rest/src/client.ts b/packages/daf-rest/src/client.ts index 919185e9a..4a6ad1aab 100644 --- a/packages/daf-rest/src/client.ts +++ b/packages/daf-rest/src/client.ts @@ -23,11 +23,13 @@ export class AgentRestClient implements IAgentPlugin { method: supportedMethods[method].type, body: JSON.stringify(args), }) + const json = await res.json() + if (res.status >= 400) { - throw Error('Bad response from server: ' + res.status + ' ' + res.statusText) + throw Error(json.error) } - return res.json() + return json } } }