Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
update to simplify how errors are reported for bad requests
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Jan 2, 2017
1 parent 9654e77 commit 5124a1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/sharepoint/queryable.ts
Expand Up @@ -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));
});
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/exceptions.ts
Expand Up @@ -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 });
}
}

Expand Down
25 changes: 11 additions & 14 deletions tests/test-config.test.ts
Expand Up @@ -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) {

Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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)));
Expand Down

0 comments on commit 5124a1e

Please sign in to comment.