mirror of
				https://github.com/gethomepage/homepage.git
				synced 2025-11-03 19:17:03 -05:00 
			
		
		
		
	Fix: refresh beszel token if empty list is returned (#5292)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									6abb3d8758
								
							
						
					
					
						commit
						f8768711da
					
				@ -72,8 +72,23 @@ export default async function beszelProxyHandler(req, res) {
 | 
				
			|||||||
        },
 | 
					        },
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if ([400, 403].includes(status)) {
 | 
					      const badRequest = [400, 403].includes(status);
 | 
				
			||||||
 | 
					      const text = data.toString("utf-8");
 | 
				
			||||||
 | 
					      let isEmpty = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        const json = JSON.parse(text);
 | 
				
			||||||
 | 
					        isEmpty = Array.isArray(json.items) && json.items.length === 0;
 | 
				
			||||||
 | 
					      } catch (err) {
 | 
				
			||||||
 | 
					        logger.debug("Failed to parse Beszel response JSON:", err);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (badRequest || isEmpty) {
 | 
				
			||||||
 | 
					        if (badRequest) {
 | 
				
			||||||
          logger.debug(`HTTP ${status} retrieving data from Beszel, logging in and trying again.`);
 | 
					          logger.debug(`HTTP ${status} retrieving data from Beszel, logging in and trying again.`);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          logger.debug(`Received empty list from Beszel, logging in and trying again.`);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        cache.del(`${tokenCacheKey}.${service}`);
 | 
					        cache.del(`${tokenCacheKey}.${service}`);
 | 
				
			||||||
        [status, token] = await login(loginUrl, widget.username, widget.password, service);
 | 
					        [status, token] = await login(loginUrl, widget.username, widget.password, service);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user