Skip to content

Commit

Permalink
Merge pull request #423 from lidofinance/fix/deprecated-api-response
Browse files Browse the repository at this point in the history
fix: depreceated api response
  • Loading branch information
itaven authored Aug 8, 2024
2 parents 12d890f + f43fb07 commit 2d8217c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pages/api/oneinch-rate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper';
import {
cacheControl,
wrapRequest as wrapNextRequest,
} from '@lidofinance/next-api-wrapper';

import { config } from 'config';
import {
Expand All @@ -24,6 +27,7 @@ export default wrapNextRequest([
cors({ origin: ['*'], methods: [HttpMethod.GET] }),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.ONEINCH_RATE),
cacheControl({ headers: config.CACHE_DEFAULT_HEADERS }),
sunsetBy({
sunsetTimestamp: API_LATER_SUNSET_TIMESTAMP,
replacementLink: getReplacementLink(API_ROUTES.ONEINCH_RATE),
Expand Down
6 changes: 5 additions & 1 deletion pages/api/short-lido-stats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper';
import {
cacheControl,
wrapRequest as wrapNextRequest,
} from '@lidofinance/next-api-wrapper';

import { config } from 'config';
import {
Expand All @@ -25,6 +28,7 @@ export default wrapNextRequest([
cors({ origin: ['*'], methods: [HttpMethod.GET] }),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.SHORT_LIDO_STATS),
cacheControl({ headers: config.CACHE_DEFAULT_HEADERS }),
sunsetBy({
sunsetTimestamp: API_LATER_SUNSET_TIMESTAMP,
replacementLink: getReplacementLink(API_ROUTES.SHORT_LIDO_STATS),
Expand Down
6 changes: 5 additions & 1 deletion pages/api/sma-steth-apr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper';
import {
cacheControl,
wrapRequest as wrapNextRequest,
} from '@lidofinance/next-api-wrapper';

import { config } from 'config';
import {
Expand All @@ -24,6 +27,7 @@ export default wrapNextRequest([
cors({ origin: ['*'], methods: [HttpMethod.GET] }),
rateLimit,
responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.SMA_STETH_APR),
cacheControl({ headers: config.CACHE_DEFAULT_HEADERS }),
sunsetBy({
sunsetTimestamp: API_DEFAULT_SUNSET_TIMESTAMP,
replacementLink: getReplacementLink(API_ROUTES.SMA_STETH_APR),
Expand Down
7 changes: 6 additions & 1 deletion utilsApi/cached-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export const createCachedProxy = ({
const cacheKey = `${proxyUrl}-${params?.toString() ?? ''}`;

const cachedValue = cache.get(cacheKey);
if (cachedValue) return cachedValue;
if (cachedValue) {
res.json(cachedValue);
return;
}

const url = proxyUrl + (params ? `?${params.toString()}` : '');

Expand All @@ -65,6 +68,8 @@ export const createCachedProxy = ({
if (e instanceof FetcherError && e.status >= 400 && e.status < 500) {
console.warn(`[CachedProxy]Forwarding ${e.status} error from ${url}`);
res.status(e.status);
res.json({ error: e.message });
return;
}
console.warn(`[CachedProxy] Failed to proxy from ${url}`, e);
res.status(500).end();
Expand Down

0 comments on commit 2d8217c

Please sign in to comment.