auth0 / angular-jwt

Library to help you work with JWTs on AngularJS
MIT License
0 stars 1 forks source link

Checks if response is undefined #183

Closed sithwarrior closed 5 years ago

sithwarrior commented 5 years ago

If a client goes offline during a request, ie looses wifi or similar, the interceptor will receive an undefined response, which causes an error, when trying to access .status

This is just an undefined check, to prevent errors at the client end.

sithwarrior commented 5 years ago

Hi @albertoperdomo . I know this isnt breaking, but our "crashalytics/error reporting" is getting a lot of these errors, when people have bad connections, and it would be nice to get i fixed.

It should take very little time to merge in.

luisrudge commented 5 years ago

@sithwarrior can you please add a test for this change? thanks!

sithwarrior commented 5 years ago

Hi @luisrudge could you then take a look at #179 because right now, the testing setup, dosent resolve correctly.

But im also not really sure how to test my commit, as all it does, is add a null check, to the response, as it can be undefined, when loosing your connection, as described in the #184 issue.

if (response.status === 401) vs if (response !== undefined && response.status === 401)

I would love to write a test, I just dont really know where to start, with this small fix.

luisrudge commented 5 years ago

I just fixed the tests, just pull latest and run npm test.

Your test should find a way to hit the responseError method with an undefined response.

sithwarrior commented 5 years ago

@luisrudge I added 2 tests. One that calls the responseError method with undefined, and another that tests that responses with 401 status, still broadcast unauthenticated.

sithwarrior commented 5 years ago

Hi @luisrudge have you had time to inspect the changes?

luisrudge commented 5 years ago

I’ll check this next week. Sorry to keep you waiting.

Luís


De: Martin Bech notifications@github.com Enviado: sexta-feira, março 8, 2019 12:24 AM Para: auth0/angular-jwt Cc: Luís Rudge; Mention Assunto: Re: [auth0/angular-jwt] Checks if response is undefined (#183)

Hi @luisrudgehttps://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fluisrudge&data=02%7C01%7C%7C263767e9cc444d61e4ff08d6a39f8144%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636876302788336543&sdata=wGjY1NgA6hz8CECZbRCwquQmy%2FhD4OHK1tIK1maf0nA%3D&reserved=0 have you had time to inspect the changes?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fauth0%2Fangular-jwt%2Fpull%2F183%23issuecomment-470846142&data=02%7C01%7C%7C263767e9cc444d61e4ff08d6a39f8144%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636876302788346547&sdata=Vg5W84oca9y6qfdP9WS4yQu2wiuCzTuNl5eXdsPd%2FiQ%3D&reserved=0, or mute the threadhttps://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAA5cE3OBCA2CQDRKdd84JsDxURLTMmm4ks5vUh5FgaJpZM4Zzcjm&data=02%7C01%7C%7C263767e9cc444d61e4ff08d6a39f8144%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636876302788356552&sdata=nxvjAE61vbkdOH34RZQrDWGExRDFT9ElfoR56C5nz2c%3D&reserved=0.

xskid commented 5 years ago

Hey guys, It would be really nice to intercept when a request got a 401 or a 404. Is this a thing already?

sithwarrior commented 5 years ago

hi @xskid it already intercepts 401 and broadcasts unauthenticated on the rootscope.

I dont think it should handle 404s