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

Retry async calls if they fail #814

Merged
merged 30 commits into from
Nov 14, 2023
Merged

Conversation

travjenkins
Copy link
Member

@travjenkins travjenkins commented Nov 2, 2023

Issues

Fixes #505
Fixes #818

Changes

505

  • Add a promise retry for when calls using the supabase API fail
  • Log when a call to supabase fails
  • Get the edge function invocation working
  • Look into how when coming back from an error can cause issues (during discover)

Misc

  • We want to log when calls fail so needed to break up the LogRocket files a bit

Tests

Manually tested

  • Used network tools to mess with the network and force failures

Screenshots

Calls failed and then succeed (success logging is no longer there)
image

A failed to fetch will show an error message stating they should check their network connection
image

Any other error will just show the error details and no longer show the "instructions" as we do not have much valuable guidance to give a user.
image

We will still show logs when available
image

@travjenkins travjenkins marked this pull request as ready for review November 9, 2023 17:41
@travjenkins travjenkins requested a review from a team as a code owner November 9, 2023 17:41
Copy link
Member

@kiahna-tucker kiahna-tucker left a comment

Choose a reason for hiding this comment

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

Approved with moderate testing.

Copy link
Member

Choose a reason for hiding this comment

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

The series of the get draft specs by x property queries make me wonder if separating these functions is the best approach. Since the shape of the response is the same, a single function could be defined (e.g., getDraftSpecs) and the query can be built up depending upon the input parameters.

// Retry calls
const RETRY_ATTEMPTS = 2;

export const supabaseRetry = <T>(makeCall: Function, action: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

There are a couple instances where an empty string is supplied to the action input parameter. Would it make sense to default this parameter to an empty string instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

No - I'd rather make it clear that the calling function is not passing an action.

import LogRocket from 'logrocket';
import { CustomEvents } from './types';

export const logRocketEvent = (
Copy link
Member

Choose a reason for hiding this comment

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

Why was this moved from src/services/logrocket.ts?

Copy link
Member Author

Choose a reason for hiding this comment

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

It causes a circular dep issue

@@ -0,0 +1,23 @@
export enum CustomEvents {
Copy link
Member

Choose a reason for hiding this comment

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

Would we like to list the members of this enumeration in alphabetical order, akin to the TABLES enumeration from src/services/supabase.ts?

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not care either way

@@ -141,6 +143,7 @@ const CTAs: ResolvedIntlConfig['messages'] = {
'cta.showAll': `Show All`,
'cta.reload': `Reload`,
'cta.evolve': `Apply`,
'cta.support': `contact support`,
Copy link
Member

@kiahna-tucker kiahna-tucker Nov 13, 2023

Choose a reason for hiding this comment

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

This CTA appears in six locations outside of 'error.instructions'. Were you thinking of replacing them in a separate PR?

A similar thing can be said for the support email, which has five additional occurrences.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah - gonna switch 'em over later on.

() =>
supabaseClient
.rpc(RPCS.CREATE_REFRESH_TOKEN, {
multi_use,
Copy link
Member

Choose a reason for hiding this comment

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

Where do you stand on using snake case for the input parameters of API-related functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really prefer snake case unless it is for something that is "from the back end". So here it kinda makes sense so that we don't have to translate the data.

// needs translated. However, Our shortest keys (cta.foo)
// can also look a lot like how Supabase returns
// errors when fetching wrong keys from a table (tableName.col).
const displayOnlyError =
Copy link
Member

Choose a reason for hiding this comment

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

This is the smallest of nits, but I believe displayErrorOnly is a better phrasing of this variable name, aligning it with flags of a similar demarcation (e.g., readOnly, nameOnly, etc.).

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@travjenkins travjenkins merged commit 4a5d971 into main Nov 14, 2023
3 checks passed
@travjenkins travjenkins deleted the travjenkins/retryAsyncFailures branch November 14, 2023 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants