RxJs call observable on error and repeat stepsStop setInterval call in JavaScriptHow to force the browser to reload cached CSS/JS files?What is the difference between call and apply?How do I return the response from an asynchronous call?What is the difference between Promises and Observables?Angular/RxJs When should I unsubscribe from `Subscription`BehaviorSubject vs Observable?RxJs Observable - Handle 404 by emitting default valuehow to make rxjs observable repeat and retryWhen run together (same index)?RxJS Observable: repeat using count and then using notifier
What benefits does the Power Word Kill spell have?
Do wheelchair aircraft exist?
How to create fractional SI units (SI...sqrts)?
Late 1970's and 6502 chip facilities for operating systems
How do pilots align the HUD with their eyeballs?
My manager quit. Should I agree to defer wage increase to accommodate budget concerns?
On the meaning of 'anyways' in "What Exactly Is a Quartz Crystal, Anyways?"
Why weren't the Death Star plans transmitted electronically?
Quick Yajilin Puzzles: Scatter and Gather
Is differentiation as a map discontinuous?
Does "as soon as" imply simultaneity?
Is the use of language other than English 'Reasonable Suspicion' for detention?
Is it more effective to add yeast before or after kneading?
Why solving a differentiated integral equation might eventually lead to erroneous solutions of the original problem?
What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?
Aesthetic proofs that involve Field Theory / Galois Theory
Is it a good idea to leave minor world details to the reader's imagination?
Can anyone put a name to this Circle of Fifths observation?
What secular civic space would pioneers build for small frontier towns?
Do we know the situation in Britain before Sealion (summer 1940)?
A famous scholar sent me an unpublished draft of hers. Then she died. I think her work should be published. What should I do?
Going to France with limited French for a day
Could Apollo astronauts see city lights from the moon?
Is there any relation/leak between two sections of LM358 op-amp?
RxJs call observable on error and repeat steps
Stop setInterval call in JavaScriptHow to force the browser to reload cached CSS/JS files?What is the difference between call and apply?How do I return the response from an asynchronous call?What is the difference between Promises and Observables?Angular/RxJs When should I unsubscribe from `Subscription`BehaviorSubject vs Observable?RxJs Observable - Handle 404 by emitting default valuehow to make rxjs observable repeat and retryWhen run together (same index)?RxJS Observable: repeat using count and then using notifier
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an observable that submits the form submit$
. This observable may end up with error with status code 403
what means that a user is not authorised and has to log in first.
Is there a way where I could on specific error code invoke another observable which performs an authorisation process. When authorisation is succeeded I want to repeat the submit$
without having user to invoke that observable once again.
To illustrate steps I want to have:
- A user tries to submit and
submit$
is being subscribed - This ends up with error with status code
403
- Observable calls another
authorise$
observable which has own workflow - When
authorise$
succeeds thesubmit$
is invoked again - The process completes with success or error
- If There is an error during
authorise$
abort thesubmit$
process
javascript angular typescript rxjs observable
add a comment
|
I have an observable that submits the form submit$
. This observable may end up with error with status code 403
what means that a user is not authorised and has to log in first.
Is there a way where I could on specific error code invoke another observable which performs an authorisation process. When authorisation is succeeded I want to repeat the submit$
without having user to invoke that observable once again.
To illustrate steps I want to have:
- A user tries to submit and
submit$
is being subscribed - This ends up with error with status code
403
- Observable calls another
authorise$
observable which has own workflow - When
authorise$
succeeds thesubmit$
is invoked again - The process completes with success or error
- If There is an error during
authorise$
abort thesubmit$
process
javascript angular typescript rxjs observable
Have you tried using retryWhen()?
– Anjil Dhamala
Mar 28 at 18:05
This sounds like work for an interceptor, especially if you have an app where user needs to be logged in to "do stuff", so the interceptor would catch all 403 errors in one place and retries the pending request(s) after successful login.
– AJT82
Mar 28 at 18:57
add a comment
|
I have an observable that submits the form submit$
. This observable may end up with error with status code 403
what means that a user is not authorised and has to log in first.
Is there a way where I could on specific error code invoke another observable which performs an authorisation process. When authorisation is succeeded I want to repeat the submit$
without having user to invoke that observable once again.
To illustrate steps I want to have:
- A user tries to submit and
submit$
is being subscribed - This ends up with error with status code
403
- Observable calls another
authorise$
observable which has own workflow - When
authorise$
succeeds thesubmit$
is invoked again - The process completes with success or error
- If There is an error during
authorise$
abort thesubmit$
process
javascript angular typescript rxjs observable
I have an observable that submits the form submit$
. This observable may end up with error with status code 403
what means that a user is not authorised and has to log in first.
Is there a way where I could on specific error code invoke another observable which performs an authorisation process. When authorisation is succeeded I want to repeat the submit$
without having user to invoke that observable once again.
To illustrate steps I want to have:
- A user tries to submit and
submit$
is being subscribed - This ends up with error with status code
403
- Observable calls another
authorise$
observable which has own workflow - When
authorise$
succeeds thesubmit$
is invoked again - The process completes with success or error
- If There is an error during
authorise$
abort thesubmit$
process
javascript angular typescript rxjs observable
javascript angular typescript rxjs observable
asked Mar 28 at 17:39
SergeySergey
1,75610 silver badges30 bronze badges
1,75610 silver badges30 bronze badges
Have you tried using retryWhen()?
– Anjil Dhamala
Mar 28 at 18:05
This sounds like work for an interceptor, especially if you have an app where user needs to be logged in to "do stuff", so the interceptor would catch all 403 errors in one place and retries the pending request(s) after successful login.
– AJT82
Mar 28 at 18:57
add a comment
|
Have you tried using retryWhen()?
– Anjil Dhamala
Mar 28 at 18:05
This sounds like work for an interceptor, especially if you have an app where user needs to be logged in to "do stuff", so the interceptor would catch all 403 errors in one place and retries the pending request(s) after successful login.
– AJT82
Mar 28 at 18:57
Have you tried using retryWhen()?
– Anjil Dhamala
Mar 28 at 18:05
Have you tried using retryWhen()?
– Anjil Dhamala
Mar 28 at 18:05
This sounds like work for an interceptor, especially if you have an app where user needs to be logged in to "do stuff", so the interceptor would catch all 403 errors in one place and retries the pending request(s) after successful login.
– AJT82
Mar 28 at 18:57
This sounds like work for an interceptor, especially if you have an app where user needs to be logged in to "do stuff", so the interceptor would catch all 403 errors in one place and retries the pending request(s) after successful login.
– AJT82
Mar 28 at 18:57
add a comment
|
1 Answer
1
active
oldest
votes
I tried an approach here where I am separating into two observables, submit$ and authenticationSubmit$, and then I merge them again. I haven't tested it, and I am writing http.post(...) twice, so it is not exactly as you described it.
import merge from 'rxjs';
import filter, switchMap from 'rxjs/operators';
...
const submit$ = http.post(...);
const authenticationAndSubmit$ = submit$.pipe(
filter(httpResponse => httpResponse.status === 403),
switchMap(() => authService.login()),
filter(authResult => authResult === 'success'),
switchMap(() => http.post(...))
);
merge(submit$, authenticationAndSubmit$)
.pipe(
filter(httpResponse => httpResponse.status === 200),
)
.subscribe(httpResponse =>
// Do something
);
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403815%2frxjs-call-observable-on-error-and-repeat-steps%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I tried an approach here where I am separating into two observables, submit$ and authenticationSubmit$, and then I merge them again. I haven't tested it, and I am writing http.post(...) twice, so it is not exactly as you described it.
import merge from 'rxjs';
import filter, switchMap from 'rxjs/operators';
...
const submit$ = http.post(...);
const authenticationAndSubmit$ = submit$.pipe(
filter(httpResponse => httpResponse.status === 403),
switchMap(() => authService.login()),
filter(authResult => authResult === 'success'),
switchMap(() => http.post(...))
);
merge(submit$, authenticationAndSubmit$)
.pipe(
filter(httpResponse => httpResponse.status === 200),
)
.subscribe(httpResponse =>
// Do something
);
add a comment
|
I tried an approach here where I am separating into two observables, submit$ and authenticationSubmit$, and then I merge them again. I haven't tested it, and I am writing http.post(...) twice, so it is not exactly as you described it.
import merge from 'rxjs';
import filter, switchMap from 'rxjs/operators';
...
const submit$ = http.post(...);
const authenticationAndSubmit$ = submit$.pipe(
filter(httpResponse => httpResponse.status === 403),
switchMap(() => authService.login()),
filter(authResult => authResult === 'success'),
switchMap(() => http.post(...))
);
merge(submit$, authenticationAndSubmit$)
.pipe(
filter(httpResponse => httpResponse.status === 200),
)
.subscribe(httpResponse =>
// Do something
);
add a comment
|
I tried an approach here where I am separating into two observables, submit$ and authenticationSubmit$, and then I merge them again. I haven't tested it, and I am writing http.post(...) twice, so it is not exactly as you described it.
import merge from 'rxjs';
import filter, switchMap from 'rxjs/operators';
...
const submit$ = http.post(...);
const authenticationAndSubmit$ = submit$.pipe(
filter(httpResponse => httpResponse.status === 403),
switchMap(() => authService.login()),
filter(authResult => authResult === 'success'),
switchMap(() => http.post(...))
);
merge(submit$, authenticationAndSubmit$)
.pipe(
filter(httpResponse => httpResponse.status === 200),
)
.subscribe(httpResponse =>
// Do something
);
I tried an approach here where I am separating into two observables, submit$ and authenticationSubmit$, and then I merge them again. I haven't tested it, and I am writing http.post(...) twice, so it is not exactly as you described it.
import merge from 'rxjs';
import filter, switchMap from 'rxjs/operators';
...
const submit$ = http.post(...);
const authenticationAndSubmit$ = submit$.pipe(
filter(httpResponse => httpResponse.status === 403),
switchMap(() => authService.login()),
filter(authResult => authResult === 'success'),
switchMap(() => http.post(...))
);
merge(submit$, authenticationAndSubmit$)
.pipe(
filter(httpResponse => httpResponse.status === 200),
)
.subscribe(httpResponse =>
// Do something
);
edited Mar 28 at 18:48
answered Mar 28 at 18:17
SnorreDanSnorreDan
8956 silver badges13 bronze badges
8956 silver badges13 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403815%2frxjs-call-observable-on-error-and-repeat-steps%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried using retryWhen()?
– Anjil Dhamala
Mar 28 at 18:05
This sounds like work for an interceptor, especially if you have an app where user needs to be logged in to "do stuff", so the interceptor would catch all 403 errors in one place and retries the pending request(s) after successful login.
– AJT82
Mar 28 at 18:57