From 3e0cd17e871ebef8febde88f69d598d87dfcb5f0 Mon Sep 17 00:00:00 2001 From: Mario Majcica Date: Tue, 22 Jan 2019 21:01:56 +0100 Subject: [PATCH] Accept error message in body as a string --- lib/RestClient.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/RestClient.ts b/lib/RestClient.ts index eca3a88..21f9b89 100644 --- a/lib/RestClient.ts +++ b/lib/RestClient.ts @@ -210,10 +210,11 @@ export class RestClient { } let obj: any; + let contents: string; // get the result from the body try { - let contents: string = await res.readBody(); + contents = await res.readBody(); if (contents && contents.length > 0) { if (options && options.deserializeDates) { obj = JSON.parse(contents, RestClient.dateTimeDeserializer); @@ -239,6 +240,9 @@ export class RestClient { // if exception/error in body, attempt to get better error if (obj && obj.message) { msg = obj.message; + } else if (contents && contents.length > 0) { + // it may be the case that the exception is in the body message as string + msg = contents; } else { msg = "Failed request: (" + statusCode + ")"; }