소스 검색

buy: don't error when no warehouse at CX

raylu 2 주 전
부모
커밋
1d2c0b6ee6
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      ts/buy.ts

+ 3 - 3
ts/buy.ts

@@ -136,16 +136,16 @@ async function warehouseInventory(username: string, apiKey: string, whName: stri
 	const warehouses: Warehouse[] = await fetch('https://rest.fnar.net/sites/warehouses/' + username,
 		{headers: {'Authorization': apiKey}}).then(r => r.json());
 	
+	const inventory = new Map<string, number>();
 	for (const warehouse of warehouses)
 		if (warehouse.LocationNaturalId === whName) {
 			const storage: Storage = await fetch(`https://rest.fnar.net/storage/${username}/${warehouse.StoreId}`,
 				{headers: {'Authorization': apiKey}}).then(r => r.json());
-			const inventory = new Map<string, number>();
 			for (const item of storage.StorageItems)
 				inventory.set(item.MaterialTicker, item.MaterialAmount);
-			return inventory;
+			break;
 		}
-	throw new Error(`couldn't find ${whName} warehouse`);
+	return inventory;
 }
 
 async function getBids(username: string, apiKey: string, cx: string) {