Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

For error handling in Slidewiki-Platform, error handler actions, error store and error components are defined. If you want to handler error in your action for incorrect parameters or service related errors, import the appropriate error handler from actions/error and call executeAction with first parameter as the imported error handler as the first parameter. This will set the ErrorStore defined in stores/ErrorStore.js .

...

Code Block
import serviceUnavailable from ../error/serviceUnavailable
...
context.service.read(..., (err, res) => {
    if (err) {
        context.executeAction(serviceUnavailable, payload, done);
        return;
    } 
    else {
           context.dispatch('LOAD_DECK_CONTENT_SUCCESS', res...);
    }
...
}


Error component

It is defined in components/Error/Error.js. Generally, one does should not have to use this component. The reason is, each error page is standalone, i.e., when an error page is shown, the other components from the platform are not used at all. Therefore, Error component is used in Application.js (at the top level) and it is called automatically. This ensures that the developer need not remember to use Error component inside one of his other components. This Error component will be called automatically whenever the error property object in ErrorStore is set. Another thing to note about this component is that this component selects appropriate child error component (e.g., BadRequest, ServiceUnavailable etc.) based on the statusCode parameter set in error property object. This component is using select statement for finding the correct child component. Child component finally renders for showing to show the error page. If you want to change the layout or css of the error page, child component is the place for that.

...

Multiple child error components are defined. One can find them in components/Error/ . For example, BadRequest.js, NotFound.js etc. One can use these individual child error components directly inside other components by calling them, for example::

Code Block
<BadRequest error={...} />

...