@@ -2100,8 +2100,24 @@ export default function (context) {
21002100 ! UI . widgets . isAudio ( subject ) &&
21012101 ! UI . widgets . isVideo ( subject )
21022102 ) {
2103+ const docUri = ( subject . doc ( ) && subject . doc ( ) . uri ) ? subject . doc ( ) . uri : '' + subject . doc ( )
2104+ const appendOutlineError = function ( detail , errObj ) {
2105+ if ( p . querySelector && docUri ) {
2106+ const existing = p . querySelector ( '[data-outline-error-for="' + docUri + '"]' )
2107+ if ( existing ) return
2108+ }
2109+ const message = UI . widgets . errorMessageBlock (
2110+ dom ,
2111+ detail ,
2112+ '#fee' ,
2113+ errObj instanceof Error ? errObj : undefined
2114+ )
2115+ if ( docUri ) message . setAttribute ( 'data-outline-error-for' , docUri )
2116+ p . appendChild ( message )
2117+ }
21032118 // Wait till at least the main URI is loaded before expanding:
2104- sf . nowOrWhenFetched ( subject . doc ( ) , undefined , function ( ok , body ) {
2119+ let errorReported = false
2120+ const fetchPromise = sf . nowOrWhenFetched ( subject . doc ( ) , undefined , function ( ok , body ) {
21052121 if ( ok ) {
21062122 sf . lookUpThing ( subject )
21072123 render ( ) // inital open, or else full if re-open
@@ -2111,14 +2127,17 @@ export default function (context) {
21112127 setUrlBarAndTitle ( subject )
21122128 }
21132129 } else {
2114- const message = dom . createElement ( 'pre' )
2115- message . textContent = body
2116- message . setAttribute ( 'style' , 'background-color: #fee;' )
2117- message . textContent =
2118- 'Outline.expand: Unable to fetch ' + subject . doc ( ) + ': ' + body
2119- p . appendChild ( message )
2130+ errorReported = true
2131+ appendOutlineError ( body , undefined )
21202132 }
21212133 } )
2134+ if ( fetchPromise && typeof fetchPromise . catch === 'function' ) {
2135+ fetchPromise . catch ( function ( err ) {
2136+ if ( errorReported ) return
2137+ errorReported = true
2138+ appendOutlineError ( err , err )
2139+ } )
2140+ }
21222141 } else {
21232142 render ( )
21242143 }
0 commit comments