Check for session token before accessing Library Account API
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Wed, 29 Jul 2015 22:07:57 +0000 (15:07 -0700)
committerJeff Davis <jdavis@sitka.bclibraries.ca>
Wed, 19 Aug 2015 18:42:04 +0000 (11:42 -0700)
This prevents a 404 error which can cause an "Authentication Required"
popup to appear in Chrome.

Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
src/od_api.coffee

index 7811f4c..a300c16 100644 (file)
@@ -214,7 +214,15 @@ define [
                #
                apiLibraryInfo: ->
 
                #
                apiLibraryInfo: ->
 
-                       get = -> od.api session.links.libraries.href
+                       get = ->
+                               if session.token.token_type?
+                                       od.api session.links.libraries.href
+                               else
+                                       # We have no token of either kind. Let's default to getting
+                                       # a library access token.
+                                       od.apiDiscAccess()
+                                       .then get, logError
+                                       .then ok
 
                        ok = (x) ->
                                session.links.update x
 
                        ok = (x) ->
                                session.links.update x