SharePoint / PnP-JS-Core

Code moved to https://github.com/pnp/pnpjs. This repository is archived.
Other
379 stars 231 forks source link

web.getFileByServerRelativeUrl().getJSON() resolves promise even if the file does not exist #795

Closed jusper-dk closed 6 years ago

jusper-dk commented 6 years ago

web.getFileByServerRelativeUrl().getJSON() always resolves promise even if the file does not exist.

Expected behavior: reject a result.

patrick-rodgers commented 6 years ago

In this case the request is coming back as a valid as a 404 isn't an error? This line should handle that as ok should be false for a 404. Can you share more of your code?

jusper-dk commented 6 years ago

For now, if file does not exist, the following code outputs an object with 'odata.error' property like if it was a content of the file: web.getFileByServerRelativeUrl().getJSON() .then(result => console.log(result))

But I expect that it rejects the promise. Here, the result should be an alert 'An error has occurred' is case the file does not exist: web.getFileByServerRelativeUrl().getJSON() .then(result => console.log(result)) .catch(result => alert('An error has occurred'))

jusper-dk commented 6 years ago

Otherwise, how can I detect that the file does not exist - make a separate request?

patrick-rodgers commented 6 years ago

I didn't look closely enough. Those shorthand methods don't check the request status before returning the result. Will have a look at updating. Thanks for reporting it.

patrick-rodgers commented 6 years ago

Fixed this in #796, will be part of next release. Thanks!

jusper-dk commented 6 years ago

Thank you! When will the release become available?