Skip to content

Commit

Permalink
feat(sentry): capture to Sentry when departure fetch fails
Browse files Browse the repository at this point in the history
  • Loading branch information
SelmaBergstrand committed Nov 29, 2024
1 parent 82c14b7 commit 791ba64
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tavla/src/Board/scenarios/QuayTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FetchErrorTypes,
} from 'Board/components/DataFetchingFailed'
import { TTheme } from 'types/settings'
import * as Sentry from '@sentry/nextjs'

export function QuayTile({
placeId,
Expand Down Expand Up @@ -42,6 +43,18 @@ export function QuayTile({
}

if (error || !data || !data.quay) {
Sentry.captureException(
new Error(
error
? 'Unknown error occurred while fetching quay departures'
: 'Departure fetch for quay returned no data',
),
{
extra: {
quayId: placeId,
},
},
)
return (
<Tile>
<DataFetchingFailed
Expand Down
13 changes: 13 additions & 0 deletions tavla/src/Board/scenarios/StopPlaceTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
FetchErrorTypes,
} from 'Board/components/DataFetchingFailed'
import { TTheme } from 'types/settings'
import * as Sentry from '@sentry/nextjs'

export function StopPlaceTile({
placeId,
Expand Down Expand Up @@ -41,6 +42,18 @@ export function StopPlaceTile({
}

if (error || !data || !data.stopPlace) {
Sentry.captureException(
new Error(
error
? 'Unknown error occurred while fetching stopPlace departures'
: 'Departure fetch for stopPlace returned no data',
),
{
extra: {
stopPlaceId: placeId,
},
},
)
return (
<Tile>
<DataFetchingFailed
Expand Down
14 changes: 14 additions & 0 deletions tavla/src/Shared/graphql/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TypedDocumentString } from './index'
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
import { formatDateToISO, addMinutesToDate } from 'utils/time'
import { FetchErrorTypes } from 'Board/components/DataFetchingFailed'
import * as Sentry from '@sentry/nextjs'

async function fetchWithTimeout(
url: RequestInfo | URL,
Expand All @@ -21,8 +22,21 @@ async function fetchWithTimeout(
} catch (error) {
clearTimeout(timeoutScheduler)
if (signal.aborted) {
Sentry.captureException(new Error('Departure fetch timed out'), {
extra: {
url: url,
fetchOptions: options,
},
})
throw new Error(FetchErrorTypes.TIMEOUT)
}
Sentry.captureException(error, {
extra: {
message: 'Unknown error occured during fetch',
url: url,
fetchOptions: options,
},
})
throw error
}
}
Expand Down

0 comments on commit 791ba64

Please sign in to comment.