Skip to Content

ODataModel: catch error when metadata failed

Nov 25, 2017 at 03:13 PM


avatar image

When an OData model is declared in the manifest and so initialized by the framework, how to detect errors when it tries to load metadata ?

For example, if the backend service is not available, or if there is an authorization issue, the call to $metadata endpoint will return a 404 or 403 error. This is logged in the console.

But, as stated in the documentation, the model.metadataLoaded() promise does not resolve in case of error. It means that if a controller try to call read() on that model later on, none of its callbacks (success / error) will resolve because internally, read() is also calling the metadataLoaded promise (which will never resolve). And so the asynchronous read() never trigger one of its callbacks..

PS: following last best practices, the component is loaded asynchronously (async=true, manifestFirst=true). So the model.attachMetadataFailed event handler is not reliable. It would be useful to have a "metadataFailed" promise, similar to the metadataLoaded...

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers