Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pchittum opened this issue Feb 2, 2021 · 5 comments

Comments

@pchittum
Copy link

pchittum commented Feb 2, 2021

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):

  • MacOS
  • Chrome
  • Salesforce API v50.0
@stale
Copy link

stale bot commented Feb 9, 2021

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

@stale stale bot added the type:bug-p3 label Feb 9, 2021
@git2gus
Copy link

git2gus bot commented Feb 9, 2021

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

@stale
Copy link

stale bot commented Apr 2, 2021

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

@stale stale bot added the type:bug-p3 label Apr 2, 2021
@uip-robot-zz
Copy link

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

@stale stale bot removed the type:bug-p3 label Apr 2, 2021
@stale
Copy link

stale bot commented Apr 10, 2021

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

@stale stale bot added the type:bug-p3 label Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants