SharePoint/PnP-JS-Core

Handling HTTP 400 Errors via catch

Closed this issue · 2 comments

Category

[ ] Enhancement

[ ] Bug

[x] Question

Version

Please specify what version of the library you are using: [ sp-pnp-js v3.0.5 ]

I hope this is the latest version, the tags in this repo have only 3.0?

Expected / Desired Behavior / Question

When making a request, i expect that using "catch()" allows me to react to errors, like stated in the wiki:
https://github.com/SharePoint/PnP-JS-Core/wiki/Basic--Operations#read-data

Observed Behavior

When trying to update a item providing a non existent field, i receive a error (HTTP 400):

fetchclient.js:7 POST https:///_api/web/lists/getByTitle('List')/items(1) 400 ()
exceptions.js:11 Uncaught (in promise) Error: Error making HttpClient request in queryable: [400]
at new t (exceptions.js:11)
at odata.js:36

Response Body:
{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"The property 'Column2' does not exist on type 'SP.Data.MyListListItem'. Make sure to only use property names that are defined by the type."}}}

I try to handle the exception by using "catch()", which is not called. Hence, i get the 2 error messages above in the developer tools console, but my catch() block is not called.

Steps to Reproduce

Have a list with and make a update to an item, providing a non existing field:

pnp.sp.web.lists.getByTitle(listTitle).items.getById(1).update({
	Column1: value1,
	Column2: value2 //<--List doesn't have a column "Column2"
}).then((item) => {
	return item;
}).catch((e) => {
	console.log("This Log Message is not printed" + e);
});

The catch block is not called. I would like to react to such an error to show a custom error message.

Thank you

Ok, cause was found. Due to misconfigured build pipeline i was using sp-pnp-js from a cdn in version 2.0.1 instead of the local 3.0.5. After fixing this the catch block is called correctly.

Sorry

No worries, was going to try and have a look at this later but glad the issue is resolved. Thanks for checking out the library!