Coder Social home page Coder Social logo

Comments (6)

gund avatar gund commented on June 11, 2024 1

What I meant by catch operator is not language try/catch construct but RxJs Observable .catch operator (like .do)

httpInterceptor.response().addInterceptor(res => {
      return res
        .do(r => doSideEffectsOnSuccess(r))
        .catch(e => handleErrorAndReturnNewObservable(e));
    });

For further details about catch operator usage please refer to RxJs catch documentation.

from ng-http-interceptor.

dsge avatar dsge commented on June 11, 2024 1

You can also use the second parameter of do():

httpInterceptor.response().addInterceptor(res => {
    return res.do(
      r => {
        console.log("Status: ", r.status);
      }, 
      err => {
        console.log("Error");
      }
    );
});

The first parameter can be replaced with null:

httpInterceptor.response().addInterceptor(res => {
    return res.do(
      null, 
      err => {
        console.log("Error");
      }
    );
});

from ng-http-interceptor.

gund avatar gund commented on June 11, 2024

In your code snippet I cannot see catch operator, maybe that is why you are missing errors?

from ng-http-interceptor.

zeqk avatar zeqk commented on June 11, 2024

I have the same error:

httpInterceptor.response().addInterceptor((res, method) => {
      try {
        return res.do(r => {
          try {
            console.log(method, r)
          }
          catch(ex){
            console.log("catcth 2", ex);
          }
          
        });
      }
      catch(ex) {
        console.log("error catch 1", ex);
      }
    });

only on success response is working

from ng-http-interceptor.

zeqk avatar zeqk commented on June 11, 2024

@gund @dsge Thanks!

from ng-http-interceptor.

gund avatar gund commented on June 11, 2024

Awesome! Will close this issue then =)

from ng-http-interceptor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.