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;
}
The error object itself returns this
{
"response": {
"size": 0,
"timeout": 0
},
"status": 400,
"statusText": "Bad Request",
"isHttpRequestError": true
}
and error.message returns this
Error making HttpClient request in queryable [400] Bad Request ::> {"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The property 'Name' does not exist on type 'SP.Data.MattersListItem'. Make sure to only use property names that are defined by the type."}}}