Error Handling

Support for unauthorized error handling is provided by several functions.

When loading an artifact returns an error, the function handleLoadError is called with an error object that has a statusCode property. If the artifact is secure and the roles and permissions of the current user do not match the ones required by the artifact, the error statusCode is 403. The default implementation of the handleLoadError will check if the user is authenticated, and if not, will call the handleLogin function. This redirects to the loginUrl provided by the Security Provider configuration.

The default implementation of the Security Provider handles status 401 and 403 errors. Other security schemes will need to implement their own security provider and specify it in the UserConfig section of the application descriptor. To implement your own security provider:

  1. Create your own class extending vb/types/securityProvider and override any method necessary.

  2. If the user information is different, make sure to match the content of the userInfo property and the type information returned by getUserInfoType(), since this determines what information is exposed in the $application.user variable.

  3. Enter your new type in the "type" section of the userConfig in app-flow.json as well as the URL to retrieve the Security Provider configuration.

Example 1-75 Example of a custom Security Provider

define(['vb/types/securityProvider'],
(SecurityProvider) => {
  class TestSecurityProvider extends SecurityProvider {
    handleLogin(returnPath) {
      // implement your own login mechanism here
    }
  }
 
  return TestSecurityProvider;
});