1

My global configuration in main.js:

http.configure(config => {
    config
      .withInterceptor({
        response(response) {
          if (response.status === 500) {
            toastr.error('Contact the tech guys.', 'Something has gone wrong!');
            throw response;
          }

          return response;
        }
      })
      .useStandardConfiguration()
      .withBaseUrl('api/blah/blah');

In my view models, I also have more handling after using http.fetch(). This is for things like using my validator to wire up error message on fields, etc.

this.http.fetch('some/route',
      {
        method: 'put',
        body: json({some: 'data'})
      })
      .then(response => response.json())
      .then(data => {
        this.otherService.doSomeStuff(data);
      })
      .catch((response) => {
        if(response.status !== 500)
          response.json()
            .then(failures => {
              this.validator.handle(failures);
            });
      });

However, I don't really want to throw response; in my interceptor (I'm doing that now because null was being passed), and, I don't want to do a response.status !== 500 check in each view model.

Is there a way to stop the chain completely with an interceptor?

steamrolla
  • 2,373
  • 1
  • 29
  • 39

0 Answers0