diff --git a/packages/binding-http/src/http-client-impl.ts b/packages/binding-http/src/http-client-impl.ts index 30c1e1b02..3344c4afa 100644 --- a/packages/binding-http/src/http-client-impl.ts +++ b/packages/binding-http/src/http-client-impl.ts @@ -128,8 +128,6 @@ export default class HttpClient implements ProtocolClient { const result = await this.doFetch(request); - this.checkFetchResponse(result); - debug(`HttpClient received headers: ${JSON.stringify(result.headers.raw())}`); debug(`HttpClient received Content-Type: ${result.headers.get("content-type")}`); @@ -154,8 +152,6 @@ export default class HttpClient implements ProtocolClient { debug(`HttpClient received ${result.status} from ${result.url}`); - this.checkFetchResponse(result); - debug(`HttpClient received headers: ${JSON.stringify(result.headers.raw())}`); } @@ -218,8 +214,6 @@ export default class HttpClient implements ProtocolClient { debug(`HttpClient received ${result.status} from ${request.url}`); debug(`HttpClient received Content-Type: ${result.headers.get("content-type")}`); - this.checkFetchResponse(result); - // in browsers node-fetch uses the native fetch, which returns a ReadableStream // not complaint with node. Therefore we have to force the conversion here. const body = ProtocolHelpers.toNodeStream(result.body as Readable); @@ -432,9 +426,13 @@ export default class HttpClient implements ProtocolClient { if (HttpClient.isOAuthTokenExpired(result, this.credential)) { this.credential = await (this.credential as OAuthCredential).refreshToken(); - return await this._fetch(await this.credential.sign(request)); + const resultAuth = await this._fetch(await this.credential.sign(request)); + this.checkFetchResponse(resultAuth); + return resultAuth; } + this.checkFetchResponse(result); + return result; } diff --git a/packages/core/src/wot-impl.ts b/packages/core/src/wot-impl.ts index ff8f3f090..1f9cca96e 100644 --- a/packages/core/src/wot-impl.ts +++ b/packages/core/src/wot-impl.ts @@ -100,7 +100,7 @@ export default class WoTImpl { return value; } - throw getLastValidationErrors(); + throw new Error("TD validation error: " + getLastValidationErrors().message); } /** @inheritDoc */