Skip to content

Commit

Permalink
Handle error fetching estimates
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Jan 7, 2024
1 parent 500c3d6 commit b1157b3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,24 @@ const Content = (props: { siteData: SiteData; estimates: Estimates }) => (
);

/**
* Returns the current fee estimates for the Bitcoin network.
* Returns the current fee estimates for the Bitcoin network, rendered as HTML.
*/
app.get('/', async (c) => {
var estimates = await getEstimates();
let estimates : Estimates | undefined;

// Set cache headers.
c.res.headers.set('Cache-Control', `public, max-age=${stdTTL}`)
try {
estimates = await getEstimates();

// Set cache headers.
c.res.headers.set('Cache-Control', `public, max-age=${stdTTL}`)

} catch (error) {
console.error(error);
estimates = {
current_block_hash: null,
fee_by_block_target: {}
};
}

const props = {
siteData: {
Expand All @@ -302,7 +313,7 @@ app.get('/', async (c) => {
});

/**
* Returns the current fee estimates for the Bitcoin network.
* Returns the current fee estimates for the Bitcoin network, rendered as JSON.
*/
app.get('/v1/fee-estimates', async (c) => {
try {
Expand Down

0 comments on commit b1157b3

Please sign in to comment.