-
Notifications
You must be signed in to change notification settings - Fork 2
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
Better error message and error handling for data plane gateway #916
Changes from all commits
e7998e7
f04e62b
de6f59c
7d43f92
8775106
f05c6f2
b281753
8fd81ef
21d0c69
8e5c924
20dcdc7
8404402
ce2ad08
addc496
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import { Box, Stack, Typography } from '@mui/material'; | ||
import { FormattedMessage, useIntl } from 'react-intl'; | ||
import { logRocketConsole, retryAfterFailure } from 'services/shared'; | ||
import { | ||
logRocketConsole, | ||
logRocketEvent, | ||
retryAfterFailure, | ||
} from 'services/shared'; | ||
import { CustomEvents } from 'services/types'; | ||
import Instructions from './Instructions'; | ||
import { ErrorDetails } from './types'; | ||
|
||
interface Props { | ||
error?: ErrorDetails; | ||
} | ||
|
||
const FALLBACK = 'error.fallBack'; | ||
|
||
function Message({ error }: Props) { | ||
// We fire an event AND log so we can find these but LR | ||
// does not allow unbounded data to be passed into an event | ||
// so the logging allows us to see what error was passed in | ||
logRocketEvent(CustomEvents.ERROR_DISPLAYED); | ||
logRocketConsole('Error message displayed', error); | ||
|
||
const intl = useIntl(); | ||
|
||
const failedAfterRetry = retryAfterFailure(error?.message ?? error); | ||
|
||
// Check if we have retried making the call or if we think the message object | ||
|
@@ -25,10 +35,17 @@ function Message({ error }: Props) { | |
(typeof error === 'object' && error.hasOwnProperty('code')) || | ||
failedAfterRetry; | ||
|
||
// There is a small chance this can happen so adding custom event to track it | ||
// Happened before when journal data hook wasn't catching errors | ||
const id = error.message ?? FALLBACK; | ||
if (id === FALLBACK) { | ||
logRocketEvent(CustomEvents.ERROR_MISSING_MESSAGE); | ||
} | ||
Comment on lines
+38
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this super safe. This spot should no longer get hit - but in case making sure we have an event just for it. We could figure this out with the event/logging above but I want to be able to search for this and not have to manually review sessions. |
||
|
||
// We do not need to translate messages from Supabase as they comeback readable | ||
const message = displayErrorOnly | ||
? error.message | ||
: intl.formatMessage({ id: error.message }); | ||
: intl.formatMessage({ id }); | ||
|
||
if (!displayErrorOnly) { | ||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,10 @@ import useGatewayAuthToken from 'hooks/useGatewayAuthToken'; | |
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
import { useCounter } from 'react-use'; | ||
import useSWR from 'swr'; | ||
|
||
enum ErrorFlags { | ||
// TOKEN_PARSING_ISSUE = 'parsing jwt:', // useful for testing just add it to the onError | ||
TOKEN_NOT_FOUND = 'Unauthenticated', | ||
TOKEN_INVALID = 'Authentication failed', | ||
OPERATION_INVALID = 'Unauthorized', | ||
} | ||
import { | ||
dataPlaneFetcher_list, | ||
shouldRefreshToken, | ||
} from 'utils/dataPlane-utils'; | ||
|
||
const errorRetryCount = 2; | ||
|
||
|
@@ -41,18 +38,28 @@ const useJournalsForCollection = (collectionName: string | undefined) => { | |
}, [gatewayConfig]); | ||
|
||
const fetcher = useCallback( | ||
(_url: string) => { | ||
async (_url: string) => { | ||
if (journalClient && collectionName) { | ||
const journalSelector = new JournalSelector().collection( | ||
collectionName | ||
); | ||
return journalClient.list(journalSelector).then((result) => { | ||
const journals = result.unwrap(); | ||
|
||
return { | ||
journals: journals.length > 0 ? journals : [], | ||
}; | ||
}); | ||
const dataPlaneListResponse = await dataPlaneFetcher_list( | ||
journalClient, | ||
journalSelector, | ||
'JournalData' | ||
); | ||
|
||
if (!Array.isArray(dataPlaneListResponse)) { | ||
return Promise.reject(dataPlaneListResponse); | ||
} | ||
|
||
return { | ||
journals: | ||
dataPlaneListResponse.length > 0 | ||
? dataPlaneListResponse | ||
: [], | ||
}; | ||
Comment on lines
+47
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made these use identical variable names to make merging these together later easier. I was going to just have the array and response in the list call but ran into typescript issues and did not want to keep trying to wrangle those. |
||
} else { | ||
return null; | ||
} | ||
|
@@ -76,12 +83,7 @@ const useJournalsForCollection = (collectionName: string | undefined) => { | |
onError: async (error) => { | ||
incAttempts(); | ||
|
||
const errorAsString = `${error}`; | ||
if ( | ||
session && | ||
(errorAsString.includes(ErrorFlags.TOKEN_INVALID) || | ||
errorAsString.includes(ErrorFlags.TOKEN_NOT_FOUND)) | ||
) { | ||
if (session && shouldRefreshToken(`${error}`)) { | ||
await refreshAuthToken(); | ||
resetAttempts(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,8 @@ const Error: ResolvedIntlConfig['messages'] = { | |
'error.hintLabel': `Hint:`, | ||
'error.descriptionLabel': `Description:`, | ||
'error.tryAgain': `Try again and if the issue persists please contact support.`, | ||
|
||
'error.fallBack': `no error details to display`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we comfortable with this terse and vague of a fallback message? If so, I would recommend using sentence case here and appending with a period. Out of curiosity, why does a generic error message -- along the lines of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The point is to keep it super vague so it is not relied on too much as it is simply a failsafe. |
||
}; | ||
|
||
const ErrorBoundry: ResolvedIntlConfig['messages'] = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
broker, | ||
JournalClient, | ||
JournalSelector, | ||
ShardClient, | ||
ShardSelector, | ||
} from 'data-plane-gateway'; | ||
import { Shard } from 'data-plane-gateway/types/shard_client'; | ||
import { ResponseError } from 'data-plane-gateway/types/util'; | ||
import { logRocketConsole } from 'services/shared'; | ||
|
||
export enum ErrorFlags { | ||
// DEBUGGING = 'parsing jwt:', // useful for testing just add it to the onError | ||
OPERATION_INVALID = 'Unauthorized', | ||
TOKEN_EXPIRED = 'token is expired', | ||
TOKEN_INVALID = 'Authentication failed', | ||
TOKEN_NOT_FOUND = 'Unauthenticated', | ||
} | ||
|
||
export const shouldRefreshToken = (errorMessage?: string | null) => { | ||
return ( | ||
errorMessage && | ||
(errorMessage.includes(ErrorFlags.TOKEN_INVALID) || | ||
errorMessage.includes(ErrorFlags.TOKEN_NOT_FOUND) || | ||
errorMessage.includes(ErrorFlags.TOKEN_EXPIRED)) | ||
); | ||
}; | ||
|
||
type AllowedKeys = 'ShardsList' | 'JournalData'; | ||
export function dataPlaneFetcher_list( | ||
client: ShardClient, | ||
selector: ShardSelector, | ||
key: 'ShardsList' | ||
): Promise<Shard[] | ResponseError['body']>; | ||
export function dataPlaneFetcher_list( | ||
client: JournalClient, | ||
selector: JournalSelector, | ||
key: 'JournalData' | ||
): Promise<broker.ProtocolJournalSpec[] | ResponseError['body']>; | ||
export async function dataPlaneFetcher_list( | ||
client: ShardClient | JournalClient, | ||
selector: ShardSelector | JournalSelector, | ||
key: AllowedKeys | ||
): Promise<Shard[] | broker.ProtocolJournalSpec[] | ResponseError['body']> { | ||
// This can throw an error! Used within fetchers within SWR that is fine and SWR will handle it | ||
// TODO (typing) | ||
// I hate this but I need to get the bug finished | ||
const result = await client.list(selector as any); | ||
|
||
// Check for an error | ||
if (result.err()) { | ||
// Unwrap the error, log the error, and reject the response | ||
const error = result.unwrap_err(); | ||
logRocketConsole(`${key} : error : `, error); | ||
return Promise.reject(error.body); | ||
} | ||
|
||
try { | ||
// No error so should be fine to unwrap | ||
const unwrappedResponse = result.unwrap(); | ||
return await Promise.resolve(unwrappedResponse); | ||
} catch (error: unknown) { | ||
// This is just here to be safe. We'll keep an eye on it and possibly remove | ||
logRocketConsole(`${key} : unwrapError : `, error); | ||
return Promise.reject(error); | ||
} | ||
Comment on lines
+45
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just snagged this from the shards hook. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping this off for right now. Will make a stand alone PR to fix all of these while turning it on.