@@ -46,9 +46,9 @@ export async function getUserWithPhoto(
4646 if ( getIsUsersCacheEnabled ( ) ) {
4747 const cache = CacheService . getCache < CacheUser > ( schemas . users , schemas . users . stores . users ) ;
4848 cachedUser = await cache . getValue ( userId || 'me' ) ;
49- if ( cachedUser && getUserInvalidationTime ( ) > Date . now ( ) - cachedUser . timeCached ) {
49+ if ( cachedUser !== undefined && getUserInvalidationTime ( ) > Date . now ( ) - cachedUser . timeCached ) {
5050 user = cachedUser . user ? JSON . parse ( cachedUser . user ) : null ;
51- if ( requestedProps ) {
51+ if ( user !== null && requestedProps ) {
5252 const uniqueProps = requestedProps . filter ( prop => ! Object . keys ( user ) . includes ( prop ) ) ;
5353 if ( uniqueProps . length >= 1 ) {
5454 user = null ;
@@ -61,7 +61,7 @@ export async function getUserWithPhoto(
6161 }
6262 if ( getIsPhotosCacheEnabled ( ) ) {
6363 cachedPhoto = await getPhotoFromCache ( userId || 'me' , schemas . photos . stores . users ) ;
64- if ( cachedPhoto && getPhotoInvalidationTime ( ) > Date . now ( ) - cachedPhoto . timeCached ) {
64+ if ( cachedPhoto !== undefined && getPhotoInvalidationTime ( ) > Date . now ( ) - cachedPhoto . timeCached ) {
6565 photo = cachedPhoto . photo ;
6666 } else if ( cachedPhoto ) {
6767 try {
@@ -119,28 +119,35 @@ export async function getUserWithPhoto(
119119 storePhotoInCache ( userId || 'me' , schemas . photos . stores . users , { eTag, photo : photo } ) ;
120120 }
121121 } else if ( ! cachedPhoto ) {
122- // if only photo or user is not cached, get it individually
123- const response = await getPhotoForResource ( graph , resource , scopes ) ;
124- if ( response ) {
125- if ( getIsPhotosCacheEnabled ( ) ) {
126- storePhotoInCache ( userId || 'me' , schemas . photos . stores . users , { eTag : response . eTag , photo : response . photo } ) ;
122+ try {
123+ // if only photo or user is not cached, get it individually
124+ const response = await getPhotoForResource ( graph , resource , scopes ) ;
125+ if ( response ) {
126+ if ( getIsPhotosCacheEnabled ( ) ) {
127+ storePhotoInCache ( userId || 'me' , schemas . photos . stores . users , {
128+ eTag : response . eTag ,
129+ photo : response . photo
130+ } ) ;
131+ }
132+ photo = response . photo ;
127133 }
128- photo = response . photo ;
129- }
134+ } catch ( _ ) { }
130135 } else if ( ! cachedUser ) {
131136 // get user from graph
132- const response = await graph
133- . api ( fullResource )
134- . middlewareOptions ( prepScopes ( ...scopes ) )
135- . get ( ) ;
137+ try {
138+ const response = await graph
139+ . api ( fullResource )
140+ . middlewareOptions ( prepScopes ( ...scopes ) )
141+ . get ( ) ;
136142
137- if ( response ) {
138- if ( getIsUsersCacheEnabled ( ) ) {
139- const cache = CacheService . getCache < CacheUser > ( schemas . users , schemas . users . stores . users ) ;
140- cache . putValue ( userId || 'me' , { user : JSON . stringify ( response ) } ) ;
143+ if ( response ) {
144+ if ( getIsUsersCacheEnabled ( ) ) {
145+ const cache = CacheService . getCache < CacheUser > ( schemas . users , schemas . users . stores . users ) ;
146+ cache . putValue ( userId || 'me' , { user : JSON . stringify ( response ) } ) ;
147+ }
148+ user = response ;
141149 }
142- user = response ;
143- }
150+ } catch ( _ ) { }
144151 }
145152
146153 if ( user ) {
0 commit comments