diff --git a/sentry.client.config.ts b/sentry.client.config.ts index c700c93..38580b0 100644 --- a/sentry.client.config.ts +++ b/sentry.client.config.ts @@ -2,29 +2,31 @@ // The config you add here will be used whenever a users loads a page in their browser. // https://docs.sentry.io/platforms/javascript/guides/nextjs/ -import * as Sentry from "@sentry/nextjs"; +import * as Sentry from '@sentry/nextjs'; -Sentry.init({ - dsn: "https://296a944ee979fb2cbb84b24658b83ac5@o4505949331390464.ingest.sentry.io/4505949333094400", +if (!process.env.NEXT_PUBLIC_IS_LOCAL) { + Sentry.init({ + dsn: 'https://296a944ee979fb2cbb84b24658b83ac5@o4505949331390464.ingest.sentry.io/4505949333094400', - // Adjust this value in production, or use tracesSampler for greater control - tracesSampleRate: 1, + // Adjust this value in production, or use tracesSampler for greater control + tracesSampleRate: 1, - // Setting this option to true will print useful information to the console while you're setting up Sentry. - debug: false, + // Setting this option to true will print useful information to the console while you're setting up Sentry. + debug: false, - replaysOnErrorSampleRate: 1.0, + replaysOnErrorSampleRate: 1.0, - // This sets the sample rate to be 10%. You may want this to be 100% while - // in development and sample at a lower rate in production - replaysSessionSampleRate: 0.1, + // This sets the sample rate to be 10%. You may want this to be 100% while + // in development and sample at a lower rate in production + replaysSessionSampleRate: 0.1, - // You can remove this option if you're not planning to use the Sentry Session Replay feature: - integrations: [ - new Sentry.Replay({ - // Additional Replay configuration goes in here, for example: - maskAllText: true, - blockAllMedia: true, - }), - ], -}); + // You can remove this option if you're not planning to use the Sentry Session Replay feature: + integrations: [ + new Sentry.Replay({ + // Additional Replay configuration goes in here, for example: + maskAllText: true, + blockAllMedia: true, + }), + ], + }); +} diff --git a/sentry.edge.config.ts b/sentry.edge.config.ts index 9ad93e9..b87d973 100644 --- a/sentry.edge.config.ts +++ b/sentry.edge.config.ts @@ -3,14 +3,16 @@ // Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally. // https://docs.sentry.io/platforms/javascript/guides/nextjs/ -import * as Sentry from "@sentry/nextjs"; +import * as Sentry from '@sentry/nextjs'; -Sentry.init({ - dsn: "https://296a944ee979fb2cbb84b24658b83ac5@o4505949331390464.ingest.sentry.io/4505949333094400", +if (!process.env.NEXT_PUBLIC_IS_LOCAL) { + Sentry.init({ + dsn: 'https://296a944ee979fb2cbb84b24658b83ac5@o4505949331390464.ingest.sentry.io/4505949333094400', - // Adjust this value in production, or use tracesSampler for greater control - tracesSampleRate: 1, + // Adjust this value in production, or use tracesSampler for greater control + tracesSampleRate: 1, - // Setting this option to true will print useful information to the console while you're setting up Sentry. - debug: false, -}); + // Setting this option to true will print useful information to the console while you're setting up Sentry. + debug: false, + }); +} diff --git a/sentry.server.config.ts b/sentry.server.config.ts index 15e52c8..90b8ea4 100644 --- a/sentry.server.config.ts +++ b/sentry.server.config.ts @@ -2,14 +2,16 @@ // The config you add here will be used whenever the server handles a request. // https://docs.sentry.io/platforms/javascript/guides/nextjs/ -import * as Sentry from "@sentry/nextjs"; +import * as Sentry from '@sentry/nextjs'; -Sentry.init({ - dsn: "https://296a944ee979fb2cbb84b24658b83ac5@o4505949331390464.ingest.sentry.io/4505949333094400", +if (!process.env.NEXT_PUBLIC_IS_LOCAL) { + Sentry.init({ + dsn: 'https://296a944ee979fb2cbb84b24658b83ac5@o4505949331390464.ingest.sentry.io/4505949333094400', - // Adjust this value in production, or use tracesSampler for greater control - tracesSampleRate: 1, + // Adjust this value in production, or use tracesSampler for greater control + tracesSampleRate: 1, - // Setting this option to true will print useful information to the console while you're setting up Sentry. - debug: false, -}); + // Setting this option to true will print useful information to the console while you're setting up Sentry. + debug: false, + }); +} diff --git a/src/pages/api/add-images-to-work-order.ts b/src/pages/api/add-images-to-work-order.ts index c50827a..8f10a38 100644 --- a/src/pages/api/add-images-to-work-order.ts +++ b/src/pages/api/add-images-to-work-order.ts @@ -7,6 +7,7 @@ import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; import { UpdateImagesSchema } from '@/types/customschemas'; import { UpdateImages } from '@/types'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -31,6 +32,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: 'Successfully added images' }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/assign-technician.ts b/src/pages/api/assign-technician.ts index 01df3e5..f4c285d 100644 --- a/src/pages/api/assign-technician.ts +++ b/src/pages/api/assign-technician.ts @@ -13,6 +13,7 @@ import { AssignTechnicianSchema } from '@/types/customschemas'; import { MISSING_ENV, errorToResponse, initializeSendgrid } from './_utils'; import { AssignTechnicianBody } from '@/types'; import { init, track } from '@amplitude/analytics-node'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -200,6 +201,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(assignedTechnician) }); } catch (error: any) { console.error(error); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/create-comment.ts b/src/pages/api/create-comment.ts index a21b27b..51b9417 100644 --- a/src/pages/api/create-comment.ts +++ b/src/pages/api/create-comment.ts @@ -9,6 +9,7 @@ import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; import { CreateCommentSchema } from '@/types/customschemas'; import { CreateComment } from '@/types'; +import * as Sentry from '@sentry/nextjs'; /** * @@ -43,6 +44,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(newComment) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/create-org.ts b/src/pages/api/create-org.ts index dcb28b7..f417a8e 100644 --- a/src/pages/api/create-org.ts +++ b/src/pages/api/create-org.ts @@ -7,6 +7,7 @@ import { API_STATUS, USER_PERMISSION_ERROR } from '@/constants'; import { ApiError, ApiResponse } from './_types'; import { CreateOrgSchema } from '@/types/customschemas'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -24,6 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(newOrg) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/create-pm.ts b/src/pages/api/create-pm.ts index af6dcff..faa1629 100644 --- a/src/pages/api/create-pm.ts +++ b/src/pages/api/create-pm.ts @@ -9,6 +9,7 @@ import { errorToResponse, initializeSendgrid } from './_utils'; import { ApiError, ApiResponse } from './_types'; import { CreatePMSchema } from '@/types/customschemas'; import { CreatePM } from '@/types'; +import * as Sentry from '@sentry/nextjs'; /** * @@ -114,6 +115,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(newPM) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/create-property.ts b/src/pages/api/create-property.ts index 1e1ac6a..18e628a 100644 --- a/src/pages/api/create-property.ts +++ b/src/pages/api/create-property.ts @@ -9,6 +9,7 @@ import { CreatePropertySchema } from '@/types/customschemas'; import { CreateProperty } from '@/types'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; /** * @@ -79,6 +80,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(newProperty) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/create-technician.ts b/src/pages/api/create-technician.ts index 1442d8c..62dcecc 100644 --- a/src/pages/api/create-technician.ts +++ b/src/pages/api/create-technician.ts @@ -9,6 +9,7 @@ import { ApiError, ApiResponse } from './_types'; import { CreateTechnician } from '@/types'; import { CreateTechnicianSchema } from '@/types/customschemas'; import { toTitleCase } from '@/utils'; +import * as Sentry from '@sentry/nextjs'; /** * @@ -116,6 +117,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(newTechnician) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/create-tenant.ts b/src/pages/api/create-tenant.ts index 5ca842c..967b2ce 100644 --- a/src/pages/api/create-tenant.ts +++ b/src/pages/api/create-tenant.ts @@ -10,6 +10,7 @@ import { CreateTenantSchema } from '@/types/customschemas'; import { ApiError, ApiResponse } from './_types'; import { INVALID_PARAM_ERROR, errorToResponse, initializeSendgrid } from './_utils'; import { CreateTenant } from '@/types'; +import * as Sentry from '@sentry/nextjs'; /** * @@ -105,6 +106,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(newTenant) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/create-work-order.ts b/src/pages/api/create-work-order.ts index b1483b3..ea32d9f 100644 --- a/src/pages/api/create-work-order.ts +++ b/src/pages/api/create-work-order.ts @@ -13,6 +13,7 @@ import { CreateWorkOrderSchema } from '@/types/customschemas'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse, initializeSendgrid } from './_utils'; import { CreateWorkOrder } from '@/types'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -303,6 +304,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: 'Successfully sent email' }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/delete.ts b/src/pages/api/delete.ts index 8cb52c1..918e362 100644 --- a/src/pages/api/delete.ts +++ b/src/pages/api/delete.ts @@ -13,6 +13,7 @@ import { DeleteEntitySchema } from '@/types/customschemas'; import { DeleteEntity } from '@/types'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -104,6 +105,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: 'Successfully deleted entity' }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.status || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-all-pms-for-org.ts b/src/pages/api/get-all-pms-for-org.ts index a6c69a9..3f8057b 100644 --- a/src/pages/api/get-all-pms-for-org.ts +++ b/src/pages/api/get-all-pms-for-org.ts @@ -7,6 +7,7 @@ import { GetPM } from '@/types'; import { GetPMSchema } from '@/types/customschemas'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -26,6 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< .json({ response: JSON.stringify({ pms: response.pms, startKey: response.startKey }) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-all-properties.ts b/src/pages/api/get-all-properties.ts index b9b0c1a..19d524d 100644 --- a/src/pages/api/get-all-properties.ts +++ b/src/pages/api/get-all-properties.ts @@ -7,6 +7,7 @@ import { GetProperties } from '@/types'; import { ApiError, ApiResponse } from './_types'; import { GetPropertiesSchema } from '@/types/customschemas'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -44,6 +45,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-all-tenants-for-org.ts b/src/pages/api/get-all-tenants-for-org.ts index 52caf39..1e3ae50 100644 --- a/src/pages/api/get-all-tenants-for-org.ts +++ b/src/pages/api/get-all-tenants-for-org.ts @@ -6,6 +6,7 @@ import { API_STATUS, USER_PERMISSION_ERROR } from '@/constants'; import { ApiError, ApiResponse } from './_types'; import { GetTenantsForOrgSchema } from '@/types/customschemas'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -31,6 +32,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-all-work-orders-for-user.ts b/src/pages/api/get-all-work-orders-for-user.ts index 53a7dbe..3085a7e 100644 --- a/src/pages/api/get-all-work-orders-for-user.ts +++ b/src/pages/api/get-all-work-orders-for-user.ts @@ -7,6 +7,7 @@ import { GetAllWorkOrdersForUserSchema } from '@/types/customschemas'; import { GetAllWorkOrdersForUser } from '@/types'; import { errorToResponse } from './_utils'; import { ApiError, ApiResponse } from './_types'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -39,6 +40,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< .json({ response: JSON.stringify({ workOrders, startKey: response.startKey }) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-images.ts b/src/pages/api/get-images.ts index 7c54788..37dd8dd 100644 --- a/src/pages/api/get-images.ts +++ b/src/pages/api/get-images.ts @@ -5,6 +5,7 @@ import { getServerSession } from 'next-auth/next'; import { options } from './auth/[...nextauth]'; import { API_STATUS, USER_PERMISSION_ERROR } from '@/constants'; import { ApiError } from './_types'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -44,7 +45,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }) ); res.status(API_STATUS.SUCCESS).json({ images }); - } catch (error) { + } catch (error: any) { + Sentry.captureException(error); // @ts-ignore res.status(API_STATUS.INTERNAL_SERVER_ERROR).send('Failed to Upload Image'); } diff --git a/src/pages/api/get-s3bucket.ts b/src/pages/api/get-s3bucket.ts index 50bfe11..17a6af1 100644 --- a/src/pages/api/get-s3bucket.ts +++ b/src/pages/api/get-s3bucket.ts @@ -8,6 +8,7 @@ import { API_STATUS, USER_PERMISSION_ERROR } from '@/constants'; import { GetS3BucketSchema } from '@/types/customschemas'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; /* * Retrieves the value for the given key from the given s3 bucket. @@ -33,6 +34,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: url }); } catch (error: any) { console.error(error); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-techs-for-org.ts b/src/pages/api/get-techs-for-org.ts index 252fd1c..56c5705 100644 --- a/src/pages/api/get-techs-for-org.ts +++ b/src/pages/api/get-techs-for-org.ts @@ -7,6 +7,7 @@ import { GetTechsForOrgSchema } from '@/types/customschemas'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; import { GetTechsForOrg } from '@/types'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -31,6 +32,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< .json({ response: JSON.stringify({ techs: response.techs, startKey: response.startKey }) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-user.ts b/src/pages/api/get-user.ts index a2ae940..1c60fce 100644 --- a/src/pages/api/get-user.ts +++ b/src/pages/api/get-user.ts @@ -7,6 +7,7 @@ import { GetUserSchema } from '@/types/customschemas'; import { GetUserBody } from '@/types'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -24,6 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(user) }); } catch (error: any) { console.error(error); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-work-order-events.ts b/src/pages/api/get-work-order-events.ts index 10e4a10..dc9e05b 100644 --- a/src/pages/api/get-work-order-events.ts +++ b/src/pages/api/get-work-order-events.ts @@ -7,6 +7,7 @@ import { GetWorkOrderEventsSchema } from '@/types/customschemas'; import { GetWorkOrderEvents } from '@/types'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -27,6 +28,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify({ events, startKey }) }); } catch (error: any) { console.error(error); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/get-work-order.ts b/src/pages/api/get-work-order.ts index b895f22..52514e4 100644 --- a/src/pages/api/get-work-order.ts +++ b/src/pages/api/get-work-order.ts @@ -7,6 +7,7 @@ import { GetSchema } from '@/types/customschemas'; import { ApiError, ApiResponse } from './_types'; import { errorToResponse } from './_utils'; import { GetBody } from '@/types'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -24,6 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(workOrder) }); } catch (error: any) { console.error(error); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/reinvite-tenants.ts b/src/pages/api/reinvite-tenants.ts index 6053c50..4a96898 100644 --- a/src/pages/api/reinvite-tenants.ts +++ b/src/pages/api/reinvite-tenants.ts @@ -10,6 +10,7 @@ import { ApiError, ApiResponse } from './_types'; import { errorToResponse, initializeSendgrid } from './_utils'; import { ReinviteTenantsSchema } from '@/types/customschemas'; import { ReinviteTenantsBody } from '@/types'; +import * as Sentry from '@sentry/nextjs'; /** * @@ -56,6 +57,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: 'true' }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/remove-technician.ts b/src/pages/api/remove-technician.ts index 1cef4d5..76083a6 100644 --- a/src/pages/api/remove-technician.ts +++ b/src/pages/api/remove-technician.ts @@ -10,6 +10,7 @@ import { RemoveTechnicianSchema } from '@/types/customschemas'; import { RemoveTechnicianBody } from '@/types'; import { errorToResponse } from './_utils'; import { toTitleCase } from '@/utils'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -53,6 +54,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(response) }); } catch (error: any) { console.error(error); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/service-request.ts b/src/pages/api/service-request.ts index 59d6333..8a64b4d 100644 --- a/src/pages/api/service-request.ts +++ b/src/pages/api/service-request.ts @@ -10,6 +10,7 @@ import { options } from './auth/[...nextauth]'; import { ApiError, ApiResponse } from './_types'; import { ChatbotRequestSchema } from '@/types/customschemas'; import { errorToResponse } from './_utils'; +import * as Sentry from '@sentry/nextjs'; const config = new Configuration({ apiKey: process.env.NEXT_PUBLIC_OPEN_AI_API_KEY, @@ -123,6 +124,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< } } catch (err: any) { const isOpenAIError = !!err?.response?.status; + Sentry.captureException(err); return res .status( isOpenAIError ? err.response.status : err?.statusCode ?? API_STATUS.INTERNAL_SERVER_ERROR diff --git a/src/pages/api/update-user.ts b/src/pages/api/update-user.ts index ebd3ce3..e90f588 100644 --- a/src/pages/api/update-user.ts +++ b/src/pages/api/update-user.ts @@ -7,6 +7,7 @@ import { errorToResponse } from './_utils'; import { UpdateUserSchema } from '@/types/customschemas'; import { UpdateUser } from '@/types'; import { ApiError, ApiResponse } from './_types'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -24,6 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(updatedUser) }); } catch (error: any) { console.error(error); + Sentry.captureException(error); return res .status(error.status || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/update-viewed-wo-list.ts b/src/pages/api/update-viewed-wo-list.ts index f40ad3b..0ef6992 100644 --- a/src/pages/api/update-viewed-wo-list.ts +++ b/src/pages/api/update-viewed-wo-list.ts @@ -9,6 +9,7 @@ import { ApiError, ApiResponse } from './_types'; import { errorToResponse, initializeSendgrid } from './_utils'; import { UpdateViewedWORequestSchema } from '@/types/customschemas'; import { UpdateViewedWORequest } from '@/types'; +import * as Sentry from '@sentry/nextjs'; /* * This function is called when a user opens a work order. @@ -91,6 +92,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(wo) }); } catch (error: any) { console.log(error); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/update-work-order.ts b/src/pages/api/update-work-order.ts index a20137d..da7e569 100644 --- a/src/pages/api/update-work-order.ts +++ b/src/pages/api/update-work-order.ts @@ -11,6 +11,7 @@ import { USER_TYPE } from '@/database/entities/user'; import { errorToResponse, initializeSendgrid } from './_utils'; import { ApiError, ApiResponse } from './_types'; import { UpdateWorkOrderSchema } from '@/types/customschemas'; +import * as Sentry from '@sentry/nextjs'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -141,6 +142,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< return res.status(API_STATUS.SUCCESS).json({ response: JSON.stringify(updatedWorkOrder) }); } catch (error: any) { console.log({ error }); + Sentry.captureException(error); return res .status(error?.statusCode || API_STATUS.INTERNAL_SERVER_ERROR) .json(errorToResponse(error)); diff --git a/src/pages/api/upload-images.ts b/src/pages/api/upload-images.ts index d87f0ca..2fddcea 100644 --- a/src/pages/api/upload-images.ts +++ b/src/pages/api/upload-images.ts @@ -5,6 +5,7 @@ import { getServerSession } from 'next-auth'; import { options } from './auth/[...nextauth]'; import { API_STATUS, USER_PERMISSION_ERROR } from '@/constants'; import { ApiError } from './_types'; +import * as Sentry from '@sentry/nextjs'; const s3 = new S3({ region: process.env.NEXT_PUBLIC_REGION, @@ -60,6 +61,7 @@ export default async function handler(req: any, res: any) { }); } catch (error: any) { console.error(error); + Sentry.captureException(error); //@ts-ignore return res .status(API_STATUS.INTERNAL_SERVER_ERROR)