I want to skip retry when specific error is thrown #7385
Answered
by
demensky
ridvandmrc
asked this question in
Q&A
-
When I get the specific error I want to make retry disabled. retryWhen(errors =>
errors.pipe(
mergeMap((error: IError, index) => {
const { name: errorName, status } = error;
if (index >= environment.retryCount) {
throw error;
}
// check error is already defined
const definedError = this.isDefinedError(status, errorName);
definedError && this.showMessage(definedError, error, errorName);
// if is not specific error retry it
if (
definedError?.retry ||
(!definedError && !this.isSuccessStatus(error.status))
) {
return of(error).pipe(delay(environment.retryDelay));
}
throw error;
}) I can not do same thing with retry. currently the code is like: catchError(error => {
const { name: errorName, status } = error;
const definedError = this.isDefinedError(status, errorName);
this.isAuthorized(definedError); // navigate to login if not authorized
!disabledError && this.showMessage(definedError, error, errorName);
// if is not specific error retry it
if (
definedError?.retry ||
(!definedError && !this.isSuccessStatus(error.status))
) {
throw error;
}
return of(error);
}),
retry({ count: environment.retryCount, delay: environment.retryDelay })
); The problem is that I can not handle the error where I use the function so they are not same. thanks in advance |
Beta Was this translation helpful? Give feedback.
Answered by
demensky
Nov 23, 2023
Replies: 1 comment 1 reply
-
I think you need to pass the function to the retry({
delay: (error) => {
console.log(error);
if (error instanceof Error && error.message === 'lol') {
// some specific error
throw error;
}
return timer(1000); // or `of(null)` for immediate
},
}) Full exampleimport { defer, retry, timer } from 'rxjs';
const names = ['foo', 'bar', 'lol', 'kek'];
defer(() => {
throw new Error(names.shift());
})
.pipe(
retry({
delay: (error) => {
console.log(error);
if (error instanceof Error && error.message === 'lol') {
// some specific error
throw error;
}
return timer(1000); // or `of(null)` for immediate
},
})
)
.subscribe({
next: (value) => {
console.log('next', value);
},
error: (error) => {
console.log('error', error);
},
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
benlesh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you need to pass the function to the
delay
parameter.Full example