Handling Errors

Errors are handled by the <View> component, which has a handleError method stored in the ViewContext. You should always use a try...catch statement around any asynchronous code that may encounter an error. Inside your catch method, you can then call context.handleError and pass the error object.

import { useContext } from 'react';
import { ViewContext } from 'components/lib';

function YourComponent(props){

  const viewContext = useContext(ViewContext);
  
  function doSomething(){
    try {
    
      ...
      
    }
    catch (err){
    
      viewContext.handleError(err);
      
    }
  }
}

This will display a banner notification along the top of the view with the error message text and also a console log.

Last updated