diff --git a/src/sharepoint/queryable.ts b/src/sharepoint/queryable.ts index 40f5391b..2c3d428b 100644 --- a/src/sharepoint/queryable.ts +++ b/src/sharepoint/queryable.ts @@ -348,8 +348,10 @@ export class Queryable { } else { - // and reject with the below message. - return reject(new ProcessHttpClientResponseException(response)); + // and reject + response.json().then(json => { + return reject(new ProcessHttpClientResponseException(response.status, response.statusText, json)); + }); } }); } diff --git a/src/utils/exceptions.ts b/src/utils/exceptions.ts index f089ee9d..511a9f3f 100644 --- a/src/utils/exceptions.ts +++ b/src/utils/exceptions.ts @@ -10,10 +10,10 @@ function defaultLog(error: Error) { */ export class ProcessHttpClientResponseException extends Error { - constructor(response: Response) { - super(`Error making HttpClient request in queryable: [${response.status}] ${response.statusText}`); + constructor(public readonly status: number, public readonly statusText: string, public readonly data: any) { + super(`Error making HttpClient request in queryable: [${status}] ${statusText}`); this.name = "ProcessHttpClientResponseException"; - response.json().then(json => Logger.log({ data: json, level: LogLevel.Error, message: this.message })); + Logger.log({ data: this.data, level: LogLevel.Error, message: this.message }); } } diff --git a/tests/test-config.test.ts b/tests/test-config.test.ts index 478c6eea..4c31614a 100644 --- a/tests/test-config.test.ts +++ b/tests/test-config.test.ts @@ -4,10 +4,11 @@ import "mocha"; import pnp from "../src/pnp"; import { Util } from "../src/utils/util"; import { Web } from "../src/sharepoint/webs"; +import { NodeFetchClient } from "../src/net/nodefetchclient"; import * as chaiAsPromised from "chai-as-promised"; chai.use(chaiAsPromised); -export let testSettings = Util.extend(global.settings.testing, { webUrl: "" }); +export let testSettings = Util.extend(global.settings.testing, { webUrl: "" }); before(function (done: MochaDone) { @@ -18,11 +19,9 @@ before(function (done: MochaDone) { if (testSettings.enableWebTests) { pnp.setup({ - nodeClientOptions: { - clientId: testSettings.clientId, - clientSecret: testSettings.clientSecret, - siteUrl: testSettings.siteUrl, - }, + fetchClientFactory: () => { + return new NodeFetchClient(testSettings.siteUrl, testSettings.clientId, testSettings.clientSecret); + } }); // comment this out to keep older subsites @@ -44,11 +43,9 @@ before(function (done: MochaDone) { // headers: { // "Accept": "application/json;odata=verbose", // }, - nodeClientOptions: { - clientId: testSettings.clientId, - clientSecret: testSettings.clientSecret, - siteUrl: url, - }, + fetchClientFactory: () => { + return new NodeFetchClient(url, testSettings.clientId, testSettings.clientSecret); + } }); done(); @@ -72,9 +69,9 @@ export function cleanUpAllSubsites() { let web = new Web(element["odata.id"], ""); web.webs.select("Title").get().then((sw: any[]) => { return Promise.all(sw.map((value) => { - let web2 = new Web(value["odata.id"], ""); - return web2.delete(); - })); + let web2 = new Web(value["odata.id"], ""); + return web2.delete(); + })); }).then(() => { web.delete(); }); }); }).catch(e => console.log("Error: " + JSON.stringify(e)));