Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1206 error responses occasionally being cached by cached utility (Revert Reversion) #1376

Conversation

mhgbrown
Copy link
Collaborator

@mhgbrown mhgbrown commented Dec 2, 2024

This PR attempts to limit the incidence of caching non-OK responses via the cached utility and fetch. Getting blog posts is method-ized and reused in places where code was being duplicated. I wanted to do the same with the api/tlv endpoint (and re-use getCmcPrices!), but didn't feel comfortable going all in without a working Etherscan api connection.

I also ran npm run format, which re-formatted src/lib/utils/puppeteer.ts...I was just working on that so it's surprising to me that it needed re-formatting ¯\(ツ)

Reverts and builds upon #1372

Copy link

railway-app bot commented Dec 2, 2024

🚅 Deployed to the app-pr-1376 environment in Drips App

Service Status Web Updated (UTC)
[Base PR] App ◻️ Removed (View Logs) Dec 4, 2024 at 1:54 pm

@mhgbrown mhgbrown linked an issue Dec 2, 2024 that may be closed by this pull request
@mhgbrown mhgbrown marked this pull request as ready for review December 2, 2024 11:10
@mhgbrown mhgbrown requested review from efstajas and jtourkos December 2, 2024 11:10
const errorContent = await driptsTokenHoldingRes.text();
// eslint-disable-next-line no-console
console.error('Etherscan returned error response', errorContent);
return new Response('[]', { headers: { 'Content-Type': 'application/json' } });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return an empty array? it usually returns a number as a string. on the actual default-explore-page.svelte it checks for typeof tlv === 'number'. I think ideally:

  • this endpoint returns either nothing or an error 500 with empty body in case there's an etherscan error
  • the logic calling in the TLV value catches an error response from this endpoint, and returns null in that case
  • default-explore-page.svelte explicitly accepts either number or null as tlv prop, and conditionally renders the TLV if tlv !== null

wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes down to change! I was following the logic in the previous lines that return an empty array if there's no etherscan key. It looks like it eventually ends up in a Intl formatting method which returns $0.0 when given an empty array...weird!

I think returning null is great in these cases. If the tlv endpoint returns a 500, the whole loading blows up as it is currently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, didn't catch that! Yeah, if there's no etherscanApiKey i think it also should be returning null and handle it the same way as when there's an error — produce a server-side log, and gracefully hide the TLV card.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes total sense, will do

@mhgbrown mhgbrown force-pushed the revert-1372-revert-1363-mhgbrown-1206-error-responses-occasionally-being-cached-by-cached-utility branch from d6e86d4 to a7e3679 Compare December 3, 2024 07:14
@mhgbrown mhgbrown merged commit 779501e into main Dec 4, 2024
5 checks passed
@mhgbrown mhgbrown deleted the revert-1372-revert-1363-mhgbrown-1206-error-responses-occasionally-being-cached-by-cached-utility branch December 4, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error responses occasionally being cached by cached utility
2 participants