Skip to content

Added support for logging Apex errors in LWC/Aura

Compare
Choose a tag to compare
@jongpie jongpie released this 03 Jun 02:31
· 107 commits to main since this release
e120ff1

Resolved #299 (requested by @arbokrad) for LWC & Aura logging by updating the JavaScript function setError() in logEntryBuilder.js to support logging both JavaScript errors and Apex controller errors:

  • Passing a JavaScript Error (existing functionality)
    const logger = this.template.querySelector('c-logger');
    const someError = new TypeError('oops');
    console.log('the JavaScript error', error);
    const entry = logger.error(this.message).setError(someError).addTag('lwc logging demo');
    console.log('entry==', JSON.parse(JSON.stringify(entry)));
  • Passing an Apex error (new functionality)
    const logger = this.template.querySelector('c-logger');
    await callSomeApexMethod()
      .then(result => {
        console.log('the result from the Apex controller', JSON.parse(JSON.stringify(result)));
      })
      .catch(error => {
        console.log('the Apex controller error', error);
        const entry = logger.error(this.message).setError(error);
        console.log('entry==', JSON.parse(JSON.stringify(entry)));
      });

This makes it easy for JS developers to pass either type of error, and Nebula Logger handles parsing the error data as needed. Below is a screenshot of the result of the new functionality of logging an Apex error - the green box shows that the LogEntry__c originated from an LWC, but the red box shows that the error logged by the LWC was an Apex error

image