Description
Description
When calling refreshApex
on an wired adapter that is in an error state (.error
property is != undefined) any refreshed/updated response from Apex Call is NOT being assigned to the .error
property of the wired property. The .error
property keeps the state of the initial error.
This will cause problem when a initially failed apex call is supposed to be repeated (e.g. a external system was temporarily not available/timed out and the user wants to re-try the request).
Steps to Reproduce
- Create LWC that wires an @AuraEnabled Apex Controller method that intentionally throws an AuraHandledException right away with current DateTime.now() as Error message:
Apex
public with sharing class ErrorSimulatorController {
@AuraEnabled(cacheable=true)
public static String simulateError() {
AuraHandledException exc = new AuraHandledException(
'Simple error message: ' + String.valueOf(DateTime.now())
);
throw exc;
}
}
JS
import { LightningElement, wire } from 'lwc';
import { refreshApex } from '@salesforce/apex';
import simulateError from '@salesforce/apex/ErrorSimulatorController.simulateError';
@wire(simulateError)
wiredResult;
handleRefresh() {
refreshApex(this.wiredResult)
}
get wired() {
return JSON.stringify(this.wiredResult);
}
- Add
{wired}
output and a button in template that onclick calls handlerhandleRefresh
HTML
<template>
<div>
{wired}
<div onclick={handleRefresh}></div>
</div>
</template>
- Click button to refresh wiredAdapter and make call to Apex.
Expected Results
The initial request to simulateError
via wiredResult
on component creation shows the first timestamp. When refreshing the wiredResult
via refreshApex
I would expect that the updated error-response from simulateError
is provisioned to the wiredResult.error
property, indicated by an updated Timestamp showing via {wired} in template.
Actual Results
In chrome dev console I can see the request to Apex is being made and having an updated timestamp in the response. However, the wiredResult.error
property keeps the response of the initial request when component was created.
Browsers Affected
Tested with Chrome 121.0.6167.139
Activity