-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
Hello teams !
First of all, thank you for the work on mutations. The API is very helpful and fits well with the Signal mental model.
I’d like to raise a question / suggestion regarding error handling when a mutation is re-triggered.
Expected / desired behavior
It would be very useful if mutationError were automatically cleared when a mutation is re-triggered, similarly to how rxResource clears its error when a new request starts.
In many UIs, the common expectation is:
- An error is shown when a mutation fails
- When the user retries the action, the previous error disappears and a new error is shown only if the retry fails again
This behavior is already implemented in rxResource, where starting a new load clears the previous error.
I use linkedSignal to bypass the problem
export default class LoginPage {
readonly userService = inject(UserService);
readonly router = inject(Router);
protected readonly loginForm = form(signal(defaultLoginFormValue), loginFormSchema);
protected mutation = rxMutation({
onSuccess: () => {
void router.navigate(['/'], { replaceUrl: true });
},
operation: (data: { email: string; password: string }) => userService.login(data),
});
protected readonly error = linkedSignal(() => {
const httpErrorResponse = this.mutation.error() as HttpErrorResponseWithReason | undefined;
return httpErrorResponse ? httpErrorResponse.error.reason : undefined;
});
login(event: SubmitEvent) {
event.preventDefault();
if (this.loginForm().valid()) {
this.error.set(undefined);
void this.mutation(this.loginForm().value());
}
}
}Thank You
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels