Skip to content

Commit

Permalink
Ignore 404 errors in Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
gruz0 committed Nov 25, 2024
1 parent 90e49d5 commit 0f697b3
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 135 deletions.
5 changes: 5 additions & 0 deletions src/app/concepts/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { notFound } from 'next/navigation'
import React from 'react'
import { App } from '@/concept/service/Service'
Expand Down Expand Up @@ -62,9 +63,13 @@ export default async function Page({ params }: { params: { id: string } }) {
notFound()
}

Sentry.captureException(e)

return <p className="p-6 text-lg">{e.message}</p>
}

Sentry.captureException(e)

return <p className="p-6 text-lg">An unexpected error occurred</p>
}
}
5 changes: 5 additions & 0 deletions src/app/ideas/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { notFound } from 'next/navigation'
import React from 'react'
import { App } from '@/idea/service/Service'
Expand All @@ -18,9 +19,13 @@ export default async function Page({ params }: { params: { id: string } }) {
notFound()
}

Sentry.captureException(e)

return <p className="p-6 text-lg">{e.message}</p>
}

Sentry.captureException(e)

return <p className="p-6 text-lg">An unexpected error occurred</p>
}
}
5 changes: 5 additions & 0 deletions src/app/ideas/[id]/social_media_campaigns/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { notFound } from 'next/navigation'
import React from 'react'
import { App } from '@/idea/service/Service'
Expand All @@ -18,9 +19,13 @@ export default async function Page({ params }: { params: { id: string } }) {
notFound()
}

Sentry.captureException(e)

return <p className="p-6 text-lg">{e.message}</p>
}

Sentry.captureException(e)

return <p className="p-6 text-lg">An unexpected error occurred</p>
}
}
22 changes: 8 additions & 14 deletions src/concept/app/queries/GetConcept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@ export class GetConceptHandler {
Sentry.setTag('query_type', 'GetConcept')
Sentry.setTag('concept_id', query.id)

try {
const concept = await this.readModel.getById(query.id)
const concept = await this.readModel.getById(query.id)

if (!concept) {
throw new NotFoundError(`Concept ${query.id} does not exist`)
}

if (!concept.isAvailable()) {
throw new ApplicationError('Concept is not available anymore')
}

return concept
} catch (e) {
Sentry.captureException(e)
if (!concept) {
throw new NotFoundError(`Concept ${query.id} does not exist`)
}

throw e
if (!concept.isAvailable()) {
throw new ApplicationError('Concept is not available anymore')
}

return concept
}
}
196 changes: 95 additions & 101 deletions src/idea/app/queries/GetIdea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,112 +93,106 @@ export class GetIdeaHandler {
Sentry.setTag('query_type', 'GetIdea')
Sentry.setTag('idea_id', query.id)

try {
const idea = await this.readModel.getById(query.id)
const idea = await this.readModel.getById(query.id)

if (!idea) {
throw new NotFoundError(`Idea ${query.id} does not exist`)
}

const valueProposition = idea.getValueProposition()
const targetAudiences = idea.getTargetAudiences()
const marketAnalysis = idea.getMarketAnalysis()
const competitorAnalysis = idea.getCompetitorAnalysis()
const productNames = idea.getProductNames()
const swotAnalysis = idea.getSWOTAnalysis()
const elevatorPitches = idea.getElevatorPitches()
const googleTrendsKeywords = idea.getGoogleTrendsKeywords()
const contentIdeasForMarketing = idea.getContentIdeasForMarketing()
if (!idea) {
throw new NotFoundError(`Idea ${query.id} does not exist`)
}

return {
id: idea.getId().getValue(),
problem: idea.getProblem().getValue(),
marketExistence: idea.getMarketExistence(),
valueProposition: valueProposition
? {
mainBenefit: valueProposition.getMainBenefit(),
problemSolving: valueProposition.getProblemSolving(),
differentiation: valueProposition.getDifferentiation(),
}
: null,
targetAudiences: targetAudiences.map((audience) => ({
id: audience.getId().getValue(),
segment: audience.getSegment(),
description: audience.getDescription(),
why: audience.getWhy(),
painPoints: audience.getPainPoints(),
targetingStrategy: audience.getTargetingStrategy(),
})),
marketAnalysis: marketAnalysis
? {
trends: marketAnalysis.getTrends(),
userBehaviors: marketAnalysis.getUserBehaviors(),
marketGaps: marketAnalysis.getMarketGaps(),
innovationOpportunities:
marketAnalysis.getInnovationOpportunities(),
strategicDirection: marketAnalysis.getStrategicDirection(),
}
: null,
competitorAnalysis: competitorAnalysis
? {
competitors: competitorAnalysis.getCompetitors(),
comparison: competitorAnalysis.getComparison(),
differentiationSuggestions:
competitorAnalysis.getDifferentiationSuggestions(),
}
: null,
productNames: productNames
? productNames.map((product) => ({
productName: product.getProductName(),
domains: product.getDomains(),
why: product.getWhy(),
tagline: product.getTagline(),
targetAudienceInsight: product.getTargetAudienceInsight(),
similarNames: product.getSimilarNames(),
brandingPotential: product.getBrandingPotential(),
}))
: null,
swotAnalysis: swotAnalysis
? {
strengths: swotAnalysis.getStrengths(),
weaknesses: swotAnalysis.getWeaknesses(),
opportunities: swotAnalysis.getOpportunities(),
threats: swotAnalysis.getThreats(),
}
: null,
elevatorPitches: elevatorPitches
? elevatorPitches.map((pitch) => ({
hook: pitch.getHook(),
problem: pitch.getProblem(),
solution: pitch.getSolution(),
valueProposition: pitch.getValueProposition(),
cta: pitch.getCTA(),
}))
: null,
googleTrendsKeywords: googleTrendsKeywords
? googleTrendsKeywords.map((keyword) => keyword.getKeyword())
: null,
contentIdeasForMarketing: contentIdeasForMarketing
? contentIdeasForMarketing.getContentIdeas().reduce(
(acc, contentIdea) => {
const section = contentIdea.getSection().getName()
const valueProposition = idea.getValueProposition()
const targetAudiences = idea.getTargetAudiences()
const marketAnalysis = idea.getMarketAnalysis()
const competitorAnalysis = idea.getCompetitorAnalysis()
const productNames = idea.getProductNames()
const swotAnalysis = idea.getSWOTAnalysis()
const elevatorPitches = idea.getElevatorPitches()
const googleTrendsKeywords = idea.getGoogleTrendsKeywords()
const contentIdeasForMarketing = idea.getContentIdeasForMarketing()

acc[section] = {
platforms: contentIdea.getPlatforms(),
ideas: contentIdea.getIdeas(),
benefits: contentIdea.getBenefits(),
}
return {
id: idea.getId().getValue(),
problem: idea.getProblem().getValue(),
marketExistence: idea.getMarketExistence(),
valueProposition: valueProposition
? {
mainBenefit: valueProposition.getMainBenefit(),
problemSolving: valueProposition.getProblemSolving(),
differentiation: valueProposition.getDifferentiation(),
}
: null,
targetAudiences: targetAudiences.map((audience) => ({
id: audience.getId().getValue(),
segment: audience.getSegment(),
description: audience.getDescription(),
why: audience.getWhy(),
painPoints: audience.getPainPoints(),
targetingStrategy: audience.getTargetingStrategy(),
})),
marketAnalysis: marketAnalysis
? {
trends: marketAnalysis.getTrends(),
userBehaviors: marketAnalysis.getUserBehaviors(),
marketGaps: marketAnalysis.getMarketGaps(),
innovationOpportunities:
marketAnalysis.getInnovationOpportunities(),
strategicDirection: marketAnalysis.getStrategicDirection(),
}
: null,
competitorAnalysis: competitorAnalysis
? {
competitors: competitorAnalysis.getCompetitors(),
comparison: competitorAnalysis.getComparison(),
differentiationSuggestions:
competitorAnalysis.getDifferentiationSuggestions(),
}
: null,
productNames: productNames
? productNames.map((product) => ({
productName: product.getProductName(),
domains: product.getDomains(),
why: product.getWhy(),
tagline: product.getTagline(),
targetAudienceInsight: product.getTargetAudienceInsight(),
similarNames: product.getSimilarNames(),
brandingPotential: product.getBrandingPotential(),
}))
: null,
swotAnalysis: swotAnalysis
? {
strengths: swotAnalysis.getStrengths(),
weaknesses: swotAnalysis.getWeaknesses(),
opportunities: swotAnalysis.getOpportunities(),
threats: swotAnalysis.getThreats(),
}
: null,
elevatorPitches: elevatorPitches
? elevatorPitches.map((pitch) => ({
hook: pitch.getHook(),
problem: pitch.getProblem(),
solution: pitch.getSolution(),
valueProposition: pitch.getValueProposition(),
cta: pitch.getCTA(),
}))
: null,
googleTrendsKeywords: googleTrendsKeywords
? googleTrendsKeywords.map((keyword) => keyword.getKeyword())
: null,
contentIdeasForMarketing: contentIdeasForMarketing
? contentIdeasForMarketing.getContentIdeas().reduce(
(acc, contentIdea) => {
const section = contentIdea.getSection().getName()

return acc
},
{} as Record<string, ContentIdeaDTO>
)
: null,
}
} catch (e) {
Sentry.captureException(e)
acc[section] = {
platforms: contentIdea.getPlatforms(),
ideas: contentIdea.getIdeas(),
benefits: contentIdea.getBenefits(),
}

throw e
return acc
},
{} as Record<string, ContentIdeaDTO>
)
: null,
}
}
}
34 changes: 14 additions & 20 deletions src/idea/app/queries/GetSocialMediaCampaigns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,23 @@ export class GetSocialMediaCampaignsHandler {
Sentry.setTag('query_type', 'GetSocialMediaCampaigns')
Sentry.setTag('idea_id', query.id)

try {
const idea = await this.readModel.getById(query.id)
const idea = await this.readModel.getById(query.id)

if (!idea) {
throw new NotFoundError(`Idea ${query.id} does not exist`)
}

const socialMediaCampaigns = idea.getSocialMediaCampaigns()
if (!idea) {
throw new NotFoundError(`Idea ${query.id} does not exist`)
}

return {
id: idea.getId().getValue(),
contents: socialMediaCampaigns
? {
shortFormContent: socialMediaCampaigns.getShortFormContents(),
longFormContent: socialMediaCampaigns.getLongFormContents(),
videoContent: socialMediaCampaigns.getVideoContents(),
}
: null,
}
} catch (e) {
Sentry.captureException(e)
const socialMediaCampaigns = idea.getSocialMediaCampaigns()

throw e
return {
id: idea.getId().getValue(),
contents: socialMediaCampaigns
? {
shortFormContent: socialMediaCampaigns.getShortFormContents(),
longFormContent: socialMediaCampaigns.getLongFormContents(),
videoContent: socialMediaCampaigns.getVideoContents(),
}
: null,
}
}
}

0 comments on commit 0f697b3

Please sign in to comment.