@@ -9,6 +9,15 @@ function handler (err, req, res, next) {
99
1010 var ldp = req . app . locals . ldp
1111
12+ if ( err . status === 401 &&
13+ req . accepts ( 'text/html' ) &&
14+ ldp . auth === 'oidc' ) {
15+ debug ( '401 error - redirect to Select Provider' )
16+ res . status ( err . status )
17+ redirectToLogin ( req , res , next )
18+ return
19+ }
20+
1221 // If the user specifies this function
1322 // then, they can customize the error programmatically
1423 if ( ldp . errorHandler ) {
@@ -18,14 +27,6 @@ function handler (err, req, res, next) {
1827 // If noErrorPages is set,
1928 // then use built-in express default error handler
2029 if ( ldp . noErrorPages ) {
21- if ( err . status === 401 &&
22- req . accepts ( 'text/html' ) &&
23- ldp . auth === 'oidc' ) {
24- debug ( 'On error pages redirect on 401' )
25- res . status ( err . status )
26- redirectToLogin ( req , res , next )
27- return
28- }
2930 res
3031 . status ( err . status )
3132 . send ( err . message + '\n' || '' )
@@ -57,7 +58,8 @@ function redirectBody (url) {
5758 <meta http-equiv="refresh" content="0; url=${ url } ">
5859</noscript>
5960<title>Redirecting...</title>
60- If you are not redirected automatically, follow the <a href='${ url } '>link to login</a>
61+ If you are not redirected automatically,
62+ follow the <a href='${ url } '>link to login</a>
6163`
6264}
6365
@@ -66,9 +68,9 @@ function redirectToLogin (req, res) {
6668 var currentUrl = util . fullUrlForReq ( req )
6769 req . session . returnToUrl = currentUrl
6870 let locals = req . app . locals
69- let loginUrl = locals . host . serverUri + '/api/auth/select-provider?returnToUrl=' +
70- currentUrl
71- debug ( 'Redirecting to login : ' + loginUrl )
71+ let loginUrl = locals . host . serverUri +
72+ '/api/auth/select-provider?returnToUrl=' + currentUrl
73+ debug ( 'Redirecting to Select Provider : ' + loginUrl )
7274
7375 var body = redirectBody ( loginUrl )
7476 res . send ( body )
0 commit comments