PnP-JS-Core icon indicating copy to clipboard operation
PnP-JS-Core copied to clipboard

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

Open jusper-dk opened this issue 8 years ago • 6 comments

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

Expected behavior: reject a result.

jusper-dk avatar Apr 30 '18 14:04 jusper-dk

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?

patrick-rodgers avatar Apr 30 '18 19:04 patrick-rodgers

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 avatar Apr 30 '18 21:04 jusper-dk

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

jusper-dk avatar Apr 30 '18 21:04 jusper-dk

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 avatar May 01 '18 16:05 patrick-rodgers

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

patrick-rodgers avatar May 01 '18 19:05 patrick-rodgers

Thank you! When will the release become available?

jusper-dk avatar May 02 '18 10:05 jusper-dk