@@ -2191,14 +2191,32 @@ export default function (context) {
21912191 ! UI . widgets . isVideo ( subject )
21922192 ) {
21932193 const docUri = ( subject . doc ( ) && subject . doc ( ) . uri ) ? subject . doc ( ) . uri : '' + subject . doc ( )
2194+ /* handle 401 errors more gracefully. For now just display a friendlier message
2195+ perhaps we can have a different page that gets shown in the future */
2196+ const unauthorizedOutlineMessage = function ( ) {
2197+ const isRootResource = ! ! ( subject && subject . uri && subject . site && subject . site ( ) . uri === subject . uri )
2198+ return isRootResource
2199+ ? 'This root resource is not publicly readable. Try logging in or opening a profile document.'
2200+ : 'This resource is not publicly readable. Try logging in or opening a different public resource.'
2201+ }
2202+ const isUnauthorizedOutlineError = function ( detail , errObj ) {
2203+ const detailText = typeof detail === 'string' ? detail : String ( detail || '' )
2204+ return errObj ?. status === 401 ||
2205+ errObj ?. response ?. status === 401 ||
2206+ detailText . includes ( 'status: 401' ) ||
2207+ detailText . includes ( 'status 401' )
2208+ }
21942209 const appendOutlineError = function ( detail , errObj ) {
21952210 if ( p . querySelector && docUri ) {
21962211 const existing = p . querySelector ( '[data-outline-error-for="' + docUri + '"]' )
21972212 if ( existing ) return
21982213 }
2214+ const friendlyDetail = isUnauthorizedOutlineError ( detail , errObj )
2215+ ? unauthorizedOutlineMessage ( )
2216+ : detail
21992217 const message = UI . widgets . errorMessageBlock (
22002218 dom ,
2201- detail ,
2219+ friendlyDetail ,
22022220 '#fee' ,
22032221 errObj instanceof Error ? errObj : undefined
22042222 )
0 commit comments