forcedotcom / lwc-dev-server-feedback

LWC Local Development
BSD 3-Clause "New" or "Revised" License
45 stars 10 forks source link

Apex exceptions raised to local server LWC components display incorrect error messages #101

Open pchittum opened 3 years ago

pchittum commented 3 years ago

Describe the bug When an exception is raised from Apex, and the LWC is being served from the LWC local dev server, there is a difference in treating that exception such that you need different code to properly surface the error in the UI. This was discovered when investigating a PR in the LWC Recipes sample app.

To Reproduce Steps to reproduce the behavior:

  1. Create an apex class and method that throws an exception. For instance a custom Apex exception.
    @AuraEnabled(Cacheable=true)
    public static List<Contact> getContactError() {
        List<Contact> contactList = new List<Contact>();
        if (contactList.size() < 5) {
            throw new CustomException('This is my error message');
        }
        return contactList;
    }

    public class CustomException extends Exception {}
  1. Call that method from an LWC.
import { LightningElement, wire } from 'lwc';
import getContactError from '@salesforce/apex/ContactController.getContactError';

export default class ApexError extends LightningElement {
    @wire(getContactError) contact;
}
  1. Run that component in local lwc server. The error is surfaced in one way. image

  2. Deploy component to an org. In that instance, the error surfaced contains the message intended from Apex. image

Expected behavior The shape of the object returned by an error should be identical between LWC when hosted in an org, and when it is hosted in the local server.

Desktop (please complete the following information):

stale[bot] commented 3 years ago

This issue has been automatically marked as type:bug-p3 because it has not had recent activity.

git2gus[bot] commented 3 years ago

This issue has been linked to a new work item: W-8868333

stale[bot] commented 3 years ago

This issue has been automatically marked as type:bug-p3 because it has not had recent activity.

uip-robot-zz commented 3 years ago

Error while creating work item. No valid build found in GUS!

stale[bot] commented 3 years ago

This issue has been automatically marked as type:bug-p3 because it has not had recent activity.