Skip to content

Commit

Permalink
feat(@dpc-sdp/nuxt-ripple-analytics): added tracking for various caug…
Browse files Browse the repository at this point in the history
…ht errors
  • Loading branch information
jeffdowdle committed Nov 28, 2024
1 parent 5ff0215 commit 390b28b
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/nuxt-ripple-analytics/utils/trackError.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
declare global {
interface Window {
newrelic?: {
noticeError: (error: Error) => void
noticeError: (error: any) => void
}
}
}

const trackError = (error: Error) => {
const trackError = (error: any) => {
if (window?.newrelic?.noticeError) {
window.newrelic.noticeError(error)
}
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt-ripple/components/TideAlerts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const filteredAlerts = computed(() => {
return !dismissedIds.includes(alert.alertId)
})
} catch (e) {
trackError(e)
console.error(
'Something went wrong when trying to get dismissed alerts cookie'
)
Expand Down
9 changes: 8 additions & 1 deletion packages/nuxt-ripple/composables/use-tide-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const useTideError = (statusCode: number): void => {
export const useTideError = (
statusCode: number,
originalError?: Error
): void => {
if (statusCode) {
switch (statusCode) {
case 404:
Expand Down Expand Up @@ -28,6 +31,10 @@ export const useTideError = (statusCode: number): void => {
break

default:
if (originalError) {
trackError(originalError)
}

throw createError({
statusCode: 500,
statusMessage: 'We have a glitch in our system.',
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt-ripple/composables/use-tide-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const useTidePage = async (
}

if (error && error.value?.statusCode) {
useTideError(error.value?.statusCode)
useTideError(error.value?.statusCode, error.value)
}

debugLogger('Page data fetched', {
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt-ripple/composables/use-tide-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useTideSite = async (id?: number): Promise<TideSiteData> => {
if (error && error.value?.statusCode) {
console.log(error)
console.log('API error fetching site data')
useTideError(500)
useTideError(500, error.value)
}

// Section.io cache tags must be set on the response header to invalidate the cache after a change in drupal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useTidePublicationChildren = async (
}
})
if (error && error.value?.statusCode) {
useTideError(error.value?.statusCode)
useTideError(error.value?.statusCode, error.value)
}
return data.value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const useTidePublicationMenu = async (
}
})
if (error && error.value?.statusCode) {
useTideError(error.value?.statusCode)
useTideError(error.value?.statusCode, error.value)
}
return data.value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const fetchSuggestions = async (query: string) => {
props.mapResultsFnName
)
} catch (e) {
trackError(e)
console.error(e)
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/ripple-tide-search/composables/useTideSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ export default ({
nextTick(onMapResultsHook.value)
}
} catch (error) {
trackError(error)
console.error(error)
searchError.value = error
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const useWebformSchema = async (
}
})
if (error && error.value?.statusCode) {
useTideError(error.value?.statusCode)
useTideError(error.value?.statusCode, error.value)
}
return data.value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export function useWebformSubmit(
window
)
} catch (e) {
trackError(e)
console.error(e)

submissionState.value = {
Expand Down Expand Up @@ -144,6 +145,7 @@ export function useWebformSubmit(
}
}
} catch (error) {
trackError(error)
console.error(error)

submissionState.value = {
Expand Down

0 comments on commit 390b28b

Please sign in to comment.