File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -222,19 +222,24 @@ export class InboxService {
222222 )
223223 }
224224
225- private _fetchAndUpdateUnreadCount ( ) : Observable < number > {
225+ private _fetchAndUpdateUnreadCount ( ) : Observable < number | null > {
226226 return this . _http
227- . get < number > ( runtimeEnvironment . BASE_URL + 'inbox/unreadCount.json' , {
228- headers : this . headers ,
229- } )
227+ . get < number > (
228+ `${ runtimeEnvironment . BASE_URL } inbox/unreadCount.json` ,
229+ { headers : this . headers , observe : 'response' } // full response
230+ )
230231 . pipe (
231- tap ( ( count : number ) => {
232- this . _unreadCountSubject . next ( count )
232+ map ( ( resp ) => {
233+ // If the server bounced us to /login, treat as “not logged in”
234+ return resp . url ?. includes ( '/login' ) ? null : resp . body ?? null
233235 } ) ,
234- catchError ( ( error ) => {
235- // If the user is not logged in and error is expected, we return null
236- return EMPTY
237- } )
236+ tap ( ( count ) => {
237+ if ( count !== null ) {
238+ // If we got a valid count, update the BehaviorSubject
239+ this . _unreadCountSubject . next ( count )
240+ }
241+ } ) ,
242+ catchError ( ( ) => EMPTY ) // If the request fails, we just return an empty observable
238243 )
239244 }
240245
You can’t perform that action at this time.
0 commit comments