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;








2















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:



  1. A user tries to submit and submit$ is being subscribed

  2. This ends up with error with status code 403

  3. Observable calls another authorise$ observable which has own workflow

  4. When authorise$ succeeds the submit$ is invoked again

  5. The process completes with success or error

  6. If There is an error during authorise$ abort the submit$ process









share|improve this question
























  • 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


















2















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:



  1. A user tries to submit and submit$ is being subscribed

  2. This ends up with error with status code 403

  3. Observable calls another authorise$ observable which has own workflow

  4. When authorise$ succeeds the submit$ is invoked again

  5. The process completes with success or error

  6. If There is an error during authorise$ abort the submit$ process









share|improve this question
























  • 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














2












2








2








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:



  1. A user tries to submit and submit$ is being subscribed

  2. This ends up with error with status code 403

  3. Observable calls another authorise$ observable which has own workflow

  4. When authorise$ succeeds the submit$ is invoked again

  5. The process completes with success or error

  6. If There is an error during authorise$ abort the submit$ process









share|improve this question














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:



  1. A user tries to submit and submit$ is being subscribed

  2. This ends up with error with status code 403

  3. Observable calls another authorise$ observable which has own workflow

  4. When authorise$ succeeds the submit$ is invoked again

  5. The process completes with success or error

  6. If There is an error during authorise$ abort the submit$ process






javascript angular typescript rxjs observable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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













1 Answer
1






active

oldest

votes


















0
















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
);





share|improve this answer





























    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
    );



    );














    draft saved

    draft discarded
















    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









    0
















    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
    );





    share|improve this answer































      0
















      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
      );





      share|improve this answer





























        0














        0










        0









        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
        );





        share|improve this answer















        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
        );






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 at 18:48

























        answered Mar 28 at 18:17









        SnorreDanSnorreDan

        8956 silver badges13 bronze badges




        8956 silver badges13 bronze badges

































            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript