Skip to content

Commit

Permalink
Revert to cached data if server is returning 500 too many requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bleunguts committed Jan 27, 2024
1 parent ba22dd6 commit 43bbca3
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions Web/src/TradingStrategyStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RootStore } from "./RootStore";
import { BackenedApi } from "./api";
import { reaction, runInAction, makeAutoObservable } from 'mobx';
import { FakeStrategyPlaceholder } from "./components/layout/DummyData";
import { FakeStrategyBTCUSD as FakeStrategyBTCUSData, FakeStrategyChartData, FakeStrategyIBMData, FakeStrategyPlaceholder } from "./components/layout/DummyData";
import { AxiosResponse } from "axios";

export interface ChartData {
Expand Down Expand Up @@ -42,8 +42,15 @@ export class TradingStrategyStore
.then((res) => this.data = ((res as AxiosResponse<never, never>).data as ChartData[]))
.catch((e) => {
console.log(`Error occurred whilst loading new symbol... ${e}`);
this.symbol = `ERROR LOADING SYMBOL..`;
this.data = FakeStrategyPlaceholder;
console.log(e);
const cache = cachedData(symbol);
if (cache != undefined){
this.data = cache as ChartData[];

} else {
this.symbol = `ERROR LOADING SYMBOL..`;
this.data = FakeStrategyPlaceholder;
}
});

console.log(`Symbol: ${symbol} loaded, data length: ${this.data.length}`);
Expand All @@ -60,13 +67,13 @@ export class TradingStrategyStore
}
}

// function fetchData(symbol: string): ChartData[] {
// switch(symbol)
// {
// case 'AAPL': return FakeStrategyChartData;
// case 'IBM' : return FakeStrategyIBMData;
// case 'BTCUSD' : return FakeStrategyBTCUSDData;
// default: throw new Error(`Cannot load data for symbol ${symbol}`);
// }
// }
function cachedData(symbol: string): ChartData[] | undefined {
switch(symbol)
{
case 'AAPL': return FakeStrategyChartData;
case 'IBM' : return FakeStrategyIBMData;
case 'BTCUSD' : return FakeStrategyBTCUSData;
default: return undefined;
}
}

0 comments on commit 43bbca3

Please sign in to comment.