const file = await fs.readFile(path.resolve(__dirname, fileName), {
encoding: null,
});
json: false
to the list of request parameter, i.e.const r = await spr.post(uri, {
body: f,
json: false,
headers: {
"X-RequestDigest": digest,
"X-HTTP-Method": "POST",
"IF-MATCH": "*",
"Content-Length": f.length,
},
});
Hey @koltyakov, I'm new to sharepoint and recently jointed a team that uses Sharepoint Online on a client's website. They were programming using Sharepoint Designer 2013, I introduced VS Code with SPGo and things are a bit better since we can publish work directly from VsCode now, but things still need improvements since there's a LOT of duplicate code between pages in /SitePages and they're using plain Javascript.
I want to introduce Typescript and some modularity into the project, I figured using WebPack is a way to start
Hey there, I'm using pnp/nodejs-commonjs with Azure Functions to add list items using a sharepoint Add-in, but I'm a bit stuck on how to catch exceptions because neither pnp-sp nor Microsoft's sharepoint REST API documentations are helpful here, or I haven't been searching very well
I came up with a hacky way on how to get 400 error messages :
async create(listTitle: string, properties: object): Promise<IItemAddResult> {
try {
const item = await sp.web.lists
.getByTitle(listTitle)
.items.add(properties);
return item;
} catch (error) {
const message = this.getErrorMessage(error);
throw new Error(message);
}
}
private getErrorMessage(error: any): string {
const mixedJson = error.message;
const index = mixedJson.indexOf('{');
return JSON.parse(mixedJson.substring(index))['odata.error'].message.value;
}