Skip to main content
Question

Unauthorized request handling in Angular.js

  • May 21, 2025
  • 1 reply
  • 29 views

Forum|alt.badge.img

Hello I developing a web app with angular.js v1.5.7, which integrates Box using oauth2 authentication in the client-side for retrive the tokens, and with them have access to the API.

 

I have a problem when the access token expires and i make a request with that expired token, I recieve a 401 (unathorized) response that I can't catch in angular because this response has a status code of -1, and this happens before i able to catch this response.

 

I made a repository in github to demostrates this behaviour https://github.com/danyfu/box-api-test, its a express server that serves on the http:localhost:3000 port the angular app.

 

It's only a button when you click do a request to the api for get the root folder of the user:

BOX_7uli2lw2sn9fqgrf8bfs1rsaa3smsrqp.png

 

When i make the request with the invalid token the response with two error logs.

https://app.box.com/s/5p551vubkeicvi4c6ohk5j24duaogbi9

 

When i make the request with a valid access token retrieve the folder info and a status of 200.

https://app.box.com/s/2mzpcgo93bumm8xhu0gv3dju9uqc3u0y

 

 

 

1 reply

Forum|alt.badge.img

You can use passport-box which will do the oauth flow in your app.

https://github.com/bluedge/passport-box

 

Here's an example where I use it as well:

https://github.com/kendomen/boxadmin