Ionic-framework: HttpInterceptor does not identify HTTP 429

Created on 11 Oct 2018  Â·  3Comments  Â·  Source: ionic-team/ionic-framework

Bug Report

Ionic Info

PS C:\Users\NOPE\Desktop\mobile-app> ionic info
√ Gathering environment info - done!

Ionic:

   ionic (Ionic CLI)  : 4.2.1 (C:\Users\NOPE\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : android 7.1.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 1.2.1, (and 13 other plugins)

System:

   Android SDK Tools : 26.1.1 (C:\Users\NOPE\AppData\Local\Android\sdk)
   NodeJS            : v8.11.2 (C:\Program Files\nodejs\node.exe)
   npm               : 6.4.1
   OS                : Windows 10

PS C:\Users\NOPE\Desktop\mobile-app>

Describe the Bug
Angular HttpInterceptor does not properly identify HTTP 429 responses

Steps to Reproduce
Steps to reproduce the behavior:

  1. Do too many http requests
  2. Expected code does not run
  3. Add some logging
  4. See error

Related Code
intercept function

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        return next.handle(req).catch(error => {
            console.log(typeof error);
            console.log(JSON.stringify(error));
            console.log(JSON.stringify(req));
            console.log(JSON.stringify(next));

            if (error instanceof HttpErrorResponse) {
                console.log((<HttpErrorResponse>error).status); // This is 0 instead of 429...
                switch ((<HttpErrorResponse>error).status) {
                    case 401: //Unauthorized
                        return this.handle401Error(req, next);
                    case 429: //Too many requests
                        return this.handle429Error(req, next);
                    default: //Other errors
                        return Observable.throw(error);
                }
            } else {
                return Observable.throw(error);
            }
        });
    }

429 Console output

{"headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"status":0,"statusText":"Unknown Error","url":null,"ok":false,"name":"HttpErrorResponse","message":"Http failure response for (unknown url): 0 Unknown Error","error":{"isTrusted":true}}
{"url":"http://10.6.10.93:86/api/Order/getPagedOrdersWithFilters?CustomerID=0&UserID=104&SortMode=OrderNumberDESC&PageSize=20&PageIndex=0&AppendLocations=true&AppendStatuses=false&AppendFiles=false&AppendCompanyRelations=false&AppendUserRelations=false&AppendVehicles=false&AppendArticles=false&AppendTimes=false&Statuses[]=1&Statuses[]=3&Statuses[]=10&Statuses[]=12","body":null,"reportProgress":false,"withCredentials":false,"responseType":"json","method":"GET","headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{},"lazyInit":null},"params":{"updates":null,"cloneFrom":null,"encoder":{},"map":null},"urlWithParams":"http://10.6.10.93:86/api/Order/getPagedOrdersWithFilters?CustomerID=0&UserID=104&SortMode=OrderNumberDESC&PageSize=20&PageIndex=0&AppendLocations=true&AppendStatuses=false&AppendFiles=false&AppendCompanyRelations=false&AppendUserRelations=false&AppendVehicles=false&AppendArticles=false&AppendTimes=false&Statuses[]=1&Statuses[]=3&Statuses[]=10&Statuses[]=12"}
{"next":{"xhrFactory":{}},"interceptor":{"tokenService":{"doc":{"location":{"href":"http://localhost:8100/","ancestorOrigins":{},"origin":"http://localhost:8100","protocol":"http:","host":"localhost:8100","hostname":"localhost","port":"8100","pathname":"/","search":"","hash":""},"__zone_symbol__devicereadyfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:deviceready","zone":"<root>","runCount":0}],"__zone_symbol__DOMContentLoadedfalse":null,"__zone_symbol__LiveReloadShutDownfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:LiveReloadShutDown","zone":"<root>","runCount":0}]},"platform":"browser","cookieName":"XSRF-TOKEN","lastCookieString":"","lastToken":null,"parseCount":0},"headerName":"X-XSRF-TOKEN"}}
0

Expected Behavior
The correct statuscode.

Additional information
Changing my authentication header to something unallowed returns HTTP 401 and the interceptor is able to detect that and runs the "handle401Error" function

401 Console output

{"headers":{"normalizedNames":{},"lazyUpdate":null},"status":401,"statusText":"Unauthorized","url":"http://10.6.10.93:86/api/Order/getPagedOrdersWithFilters?CustomerID=0&UserID=104&SortMode=null&PageSize=2000000000&PageIndex=0&AppendLocations=false&AppendStatuses=false&AppendFiles=false&AppendCompanyRelations=false&AppendUserRelations=false&AppendVehicles=false&AppendArticles=false&AppendTimes=false&StartDate=2018-10-08&EndDate=2018-10-15","ok":false,"name":"HttpErrorResponse","message":"Http failure response for http://10.6.10.93:86/api/Order/getPagedOrdersWithFilters?CustomerID=0&UserID=104&SortMode=null&PageSize=2000000000&PageIndex=0&AppendLocations=false&AppendStatuses=false&AppendFiles=false&AppendCompanyRelations=false&AppendUserRelations=false&AppendVehicles=false&AppendArticles=false&AppendTimes=false&StartDate=2018-10-08&EndDate=2018-10-15: 401 Unauthorized","error":null}
{"url":"http://10.6.10.93:86/api/Order/getPagedOrdersWithFilters?CustomerID=0&UserID=104&SortMode=null&PageSize=2000000000&PageIndex=0&AppendLocations=false&AppendStatuses=false&AppendFiles=false&AppendCompanyRelations=false&AppendUserRelations=false&AppendVehicles=false&AppendArticles=false&AppendTimes=false&StartDate=2018-10-08&EndDate=2018-10-15","body":null,"reportProgress":false,"withCredentials":false,"responseType":"json","method":"GET","headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{},"lazyInit":null},"params":{"updates":null,"cloneFrom":null,"encoder":{},"map":null},"urlWithParams":"http://10.6.10.93:86/api/Order/getPagedOrdersWithFilters?CustomerID=0&UserID=104&SortMode=null&PageSize=2000000000&PageIndex=0&AppendLocations=false&AppendStatuses=false&AppendFiles=false&AppendCompanyRelations=false&AppendUserRelations=false&AppendVehicles=false&AppendArticles=false&AppendTimes=false&StartDate=2018-10-08&EndDate=2018-10-15"}
{"next":{"xhrFactory":{}},"interceptor":{"tokenService":{"doc":{"location":{"href":"http://localhost:8100/","ancestorOrigins":{},"origin":"http://localhost:8100","protocol":"http:","host":"localhost:8100","hostname":"localhost","port":"8100","pathname":"/","search":"","hash":""},"__zone_symbol__devicereadyfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:deviceready","zone":"<root>","runCount":0}],"__zone_symbol__DOMContentLoadedfalse":null,"__zone_symbol__LiveReloadShutDownfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:LiveReloadShutDown","zone":"<root>","runCount":0}],"jQuery331079128943154441481":{"events":{"touchstart":[{"type":"touchstart","origType":"touchstart","guid":1,"namespace":"_listener0"}],"touchcancel":[{"type":"touchcancel","origType":"touchcancel","guid":2,"namespace":"_listener0"}],"touchend":[{"type":"touchend","origType":"touchend","guid":3,"namespace":"_listener0"}],"mousedown":[{"type":"mousedown","origType":"mousedown","guid":4,"namespace":"_listener0"}],"mousemove":[{"type":"mousemove","origType":"mousemove","guid":5,"namespace":"_listener0"}],"mouseup":[{"type":"mouseup","origType":"mouseup","guid":6,"namespace":"_listener0"}],"click":[{"type":"click","origType":"click","guid":7,"namespace":"_listener0"}],"selectstart":[{"type":"selectstart","origType":"selectstart","guid":8,"namespace":"_listener0"}],"contextmenu":[{"type":"contextmenu","origType":"contextmenu","guid":9,"namespace":"_listener0"}],"dragstart":[{"type":"dragstart","origType":"dragstart","guid":70,"namespace":"_listener2"},{"type":"dragstart","origType":"dragstart","guid":70,"namespace":"_listener3"}],"sortstart":[{"type":"sortstart","origType":"sortstart","guid":70,"namespace":"_listener2"},{"type":"sortstart","origType":"sortstart","guid":70,"namespace":"_listener3"}]}},"__zone_symbol__touchstartfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:touchstart","zone":"<root>","runCount":0}],"__zone_symbol__touchcancelfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:touchcancel","zone":"<root>","runCount":0}],"__zone_symbol__touchendfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:touchend","zone":"<root>","runCount":0}],"__zone_symbol__mousedownfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:mousedown","zone":"<root>","runCount":0}],"__zone_symbol__mousemovefalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:mousemove","zone":"<root>","runCount":0}],"__zone_symbol__mouseupfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:mouseup","zone":"<root>","runCount":0}],"__zone_symbol__clickfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:click","zone":"<root>","runCount":0}],"__zone_symbol__selectstartfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:selectstart","zone":"<root>","runCount":0}],"__zone_symbol__contextmenufalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:contextmenu","zone":"<root>","runCount":0}],"__zone_symbol__dragstartfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:dragstart","zone":"<root>","runCount":0}],"__zone_symbol__sortstartfalse":[{"type":"eventTask","state":"scheduled","source":"HTMLDocument.addEventListener:sortstart","zone":"<root>","runCount":0}]},"platform":"browser","cookieName":"XSRF-TOKEN","lastCookieString":"","lastToken":null,"parseCount":0},"headerName":"X-XSRF-TOKEN"}}
401

Chrome debugger
401
capture4
429
capture

Postman
429 body
capture2
429 response headers
capture3

401 response headers (no body given)
capture5

v3

Most helpful comment

This issue has nothing to do with the Ionic-Framework and is Angular specific.

All 3 comments

This issue has nothing to do with the Ionic-Framework and is Angular specific.

This issue has been automatically identified as an Ionic 3 issue. We recently moved Ionic 3 to its own repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.

If I've made a mistake, and if this issue is still relevant to Ionic 4, please let the Ionic Framework team know!

Thank you for using Ionic!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexbainbridge picture alexbainbridge  Â·  3Comments

vswarte picture vswarte  Â·  3Comments

manucorporat picture manucorporat  Â·  3Comments

MrBokeh picture MrBokeh  Â·  3Comments

RobFerguson picture RobFerguson  Â·  3Comments