Details
Description
The current code is already getting stuck in the error handling. The API as specified in the solution description does not have any way to communicate errors back to the caller, so all it can do is log errors to the JavaScript console. That does not scale.
After discussion with mdokolin we decided to switch to Promises:
- UiExtension.register() should return a promise
- The promise is resolved with the 'ui' object when everything goes well
- The promise is rejected with an 'error' object when something goes wrong. The 'error' object has two properties: 'code' (which can be used by code to understand the error case) and 'message' (a human-readable explanation of the error).
- The errors generated by Penpal should be converted to our own error format, since we don't want to expose any Penpal internals / error codes. This gives us the freedom to change the underlying library without changing the API if we want.
- It should be possible to change the promise constructor via configuration passed to the 'register' call. For example, to use $q as the promise constructor:
UiExtension.register({ Promise: $q })