Skip to content

Commit

Permalink
fix: errors from zendesk api (#18345)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Nov 2, 2023
1 parent 1a3c071 commit 9db468b
Showing 1 changed file with 42 additions and 34 deletions.
76 changes: 42 additions & 34 deletions frontend/src/lib/components/Support/supportLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,43 +258,51 @@ export const supportLogic = kea<supportLogicType>([
},
},
}
await fetch('https://posthoghelp.zendesk.com/api/v2/requests.json', {
method: 'POST',
body: JSON.stringify(payload, undefined, 4),
headers: { 'Content-Type': 'application/json' },
})
.then((res) => res.json())
.then((res) => {
const zendesk_ticket_id = res.request.id
const zendesk_ticket_link = `https://posthoghelp.zendesk.com/agent/tickets/${zendesk_ticket_id}`
const properties = {
zendesk_ticket_uuid,
kind,
target_area,
message,
zendesk_ticket_id,
zendesk_ticket_link,
}
posthog.capture('support_ticket', properties)
Sentry.captureMessage('User submitted Zendesk ticket', {
tags: {
zendesk_ticket_uuid,
zendesk_ticket_link,
support_request_kind: kind,
support_request_area: target_area,
team_id: teamLogic.values.currentTeamId,
},
extra: properties,
level: 'log',
})
lemonToast.success(
"Got the message! If we have follow-up information for you, we'll reply via email."
)

try {
const response = await fetch('https://posthoghelp.zendesk.com/api/v2/requests.json', {
method: 'POST',
body: JSON.stringify(payload, undefined, 4),
headers: { 'Content-Type': 'application/json' },
})
.catch((err) => {
captureException(err)
if (!response.ok) {
const error = new Error(`There was an error creating the support ticket with zendesk.`)
captureException(error, {
extra: { response, payload },
})
lemonToast.error(`There was an error sending the message.`)
return
}

const json = await response.json()

const zendesk_ticket_id = json.request.id
const zendesk_ticket_link = `https://posthoghelp.zendesk.com/agent/tickets/${zendesk_ticket_id}`
const properties = {
zendesk_ticket_uuid,
kind,
target_area,
message,
zendesk_ticket_id,
zendesk_ticket_link,
}
posthog.capture('support_ticket', properties)
Sentry.captureMessage('User submitted Zendesk ticket', {
tags: {
zendesk_ticket_uuid,
zendesk_ticket_link,
support_request_kind: kind,
support_request_area: target_area,
team_id: teamLogic.values.currentTeamId,
},
extra: properties,
level: 'log',
})
lemonToast.success("Got the message! If we have follow-up information for you, we'll reply via email.")
} catch (e) {
captureException(e)
lemonToast.error(`There was an error sending the message.`)
}
},

closeSupportForm: () => {
Expand Down

0 comments on commit 9db468b

Please sign in to comment.