LightningErrorHandler
No description available
Install / Use
/learn @mshanemc/LightningErrorHandlerREADME
Lightning Error Handler
This is just the error handler bits from /mshanemc/ltngbase. I'm trying to unbundle that now that sfdx and it's oss plugin make it easy to add repos from github.
displays errors from apex callbacks or force:recordData. I prefer option 1 whenever possible.
option 1 (method) --Preferred
If each component that wants to throw an error wants to host its own error handler, you can use a simpler version.
<c:LightningErrorHandler aura:id="leh"/>
example of apex callback (where a is the callback response)
if (state === "SUCCESS") {
//do your happy path logic
} else if (state === "ERROR") {
component.find('leh').passErrors(a.getError());
The error handler will only respond to method calls from its parent component.
example using Lightning Data Service/force:recordData in EDIT mode where the aura:id is "frd"
component.find("frd").saveRecord(
$A.getCallback(function(saveResult){
if (saveResult.state === "SUCCESS"){
//happy path logic here
} else if (saveResult.state === "ERROR"){
component.find("leh").passErrors(saveResult.error);
}
})
)
option 2 (event)
<aura:registerEvent name="handleCallbackError" type="c:handleCallbackError"/>
<c:LightningErrorHandler />
Simply pass in the errors object from .getErrors to a handleCallbackError event and it'll handle the rest. You can optionally name the ErrorHandler and put that name in the handleCallbackError event
Install like this:
example of callback (where a is the callback response)
if (state === "SUCCESS") {
//do your happy path logic
} else if (state === "ERROR") {
var appEvent = $A.get("e.c:handleCallbackError");
appEvent.setParams({
"errors" : a.getError()
});
appEvent.fire();
If you have multiple of these on the page, you can also scope errors to a specific instance of LightningErrorHanlder like this:
<aura:registerEvent name="handleCallbackError" type="c:handleCallbackError"/>
<c:LightningErrorHandler errorHandlerName="specificName"/>
Then pass that LEH's name when you fire the error event:
if (state === "SUCCESS") {
//do your happy path logic
} else if (state === "ERROR") {
var appEvent = $A.get("e.c:handleCallbackError");
appEvent.setParams({
"errors" : a.getError(),
"errorComponentName" : "specificName"
});
appEvent.fire();
Limitations
- I haven't built duplicate handling yet.
- I haven't done any sort of event bubbling management (stopPropogation, etc) if you're using option 1, so be cautious about hanging one of these on every branch of your component tree and firing off events. :)
- I recommend using option1 only where you know there's only one of these on the page, or you very carefully apply the ErrorHandlerName
Install
from source via web
<a href="https://githubsfdeploy.herokuapp.com?owner=mshanemc&repo=LightningErrorHandler"> <img alt="Deploy to Salesforce" src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png"/> </a>from source with sfdx to scratch org
git clone https://github.com/mshanemc/LightningErrorHandler
sfdx force:source:push -u usernameOrAlias
from source with sfdx to sandbox/production org
git clone https://github.com/mshanemc/LightningErrorHandler
sfdx force:mdapi:deploy -w 15 -d src -u usernameOrAlias
as a managed package
Namespace is shane: so all the instructions above need to be adjusted for the namespace where c: was shown
Deploy as a managed package
as a package2.0 DCP-Unlocked
no namespace.
Deploy as a unlocked
Related Skills
node-connect
341.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.6kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.6kCommit, push, and open a PR
