Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

update handleError to pass sentry context (#38411)

Jordi Enricc61026e530eb
diff --git a/apps/studio/data/feedback/support-ticket-send.ts b/apps/studio/data/feedback/support-ticket-send.ts
index 137215c244f..2a6b39cdbac 100644
--- a/apps/studio/data/feedback/support-ticket-send.ts
+++ b/apps/studio/data/feedback/support-ticket-send.ts
@@ -52,7 +52,16 @@ export async function sendSupportTicket({
},
})
- if (error) handleError(error, { alwaysCapture: true })
+ if (error) {
+ handleError(error, {
+ alwaysCapture: true,
+ sentryContext: {
+ tags: {
+ dashboardSupportForm: true,
+ },
+ },
+ })
+ }
return data
}
diff --git a/apps/studio/data/fetchers.ts b/apps/studio/data/fetchers.ts
index 99e010f7c86..f0ca332c3b5 100644
--- a/apps/studio/data/fetchers.ts
+++ b/apps/studio/data/fetchers.ts
@@ -1,13 +1,14 @@
import * as Sentry from '@sentry/nextjs'
+
import createClient from 'openapi-fetch'
+import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
import { IS_PLATFORM } from 'common'
import { API_URL } from 'lib/constants'
import { getAccessToken } from 'lib/gotrue'
import { uuidv4 } from 'lib/helpers'
import { ResponseError } from 'types'
import type { paths } from './api' // generated from openapi-typescript
-import { DEFAULT_PLATFORM_APPLICATION_NAME } from '@supabase/pg-meta/src/constants'
const DEFAULT_HEADERS = { Accept: 'application/json' }
@@ -135,15 +136,13 @@ export const {
type HandleErrorOptions = {
alwaysCapture?: boolean
+ sentryContext?: Parameters<typeof Sentry.captureException>[1]
}
-export const handleError = (
- error: unknown,
- options: HandleErrorOptions = { alwaysCapture: false }
-): never => {
+export const handleError = (error: unknown, options: HandleErrorOptions = {}): never => {
if (error && typeof error === 'object') {
if (options.alwaysCapture) {
- Sentry.captureException(error)
+ Sentry.captureException(error, options.sentryContext)
}
const errorMessage =
'msg' in error && typeof error.msg === 'string'
@@ -169,7 +168,7 @@ export const handleError = (
// the error doesn't have a message or msg property, so we can't throw it as an error. Log it via Sentry so that we can
// add handling for it.
- Sentry.captureException(error)
+ Sentry.captureException(error, options.sentryContext)
// throw a generic error if we don't know what the error is. The message is intentionally vague because it might show
// up in the UI.
diff --git a/apps/studio/data/permissions/permissions-query.ts b/apps/studio/data/permissions/permissions-query.ts
index bad66b84e72..3f5375e468f 100644
--- a/apps/studio/data/permissions/permissions-query.ts
+++ b/apps/studio/data/permissions/permissions-query.ts
@@ -12,10 +12,13 @@ export type PermissionsResponse = Permission[]
export async function getPermissions(signal?: AbortSignal) {
const { data, error } = await get('/platform/profile/permissions', { signal })
if (error) {
- handleError(error)
- Sentry.withScope(function (scope) {
- scope.setTag('permissions-query-error', true)
- Sentry.captureException(error)
+ handleError(error, {
+ alwaysCapture: true,
+ sentryContext: {
+ tags: {
+ permissionsQuery: true,
+ },
+ },
})
}