Skip to content

Commit 94d5b81

Browse files
committed
fix-jun-5
1 parent 32b711d commit 94d5b81

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/app/core/inbox/inbox.service.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)