Skip to content

Commit

Permalink
Improves error reporting for SMS and backup unsubscribe events (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushchris authored Feb 7, 2024
1 parent 8de5cb4 commit 97e5e0b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion apps/platform/src/error/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface ErrorHandlerTypeConfig extends DriverConfig {
driver: ErrorHandlerProviderName
}

export class ContextError extends Error {
context?: Record<string, any>
}

export default class ErrorHandler {
provider?: ErrorHandlerProvider
constructor(config: ErrorConfig) {
Expand All @@ -25,6 +29,11 @@ export default class ErrorHandler {
}

notify(error: Error, context?: Record<string, any>) {
this.provider?.notify(error, context)
this.provider?.notify(
error,
error instanceof ContextError
? { ...context, ...error.context }
: context,
)
}
}
2 changes: 1 addition & 1 deletion apps/platform/src/providers/text/TextChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class TextChannel {
// If for some reason we are getting an unsubscribe error
// force unsubscribe the user from this subscription type
if (error instanceof UnsubscribeTextError) {
unsubscribe(variables.user.id, variables.context.subscription_id)
await unsubscribe(variables.user.id, variables.context.subscription_id)
}
throw error
}
Expand Down
7 changes: 5 additions & 2 deletions apps/platform/src/providers/text/TextError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export default class TextError extends Error {
import { ContextError } from '../../error/ErrorHandler'

export default class TextError extends ContextError {
phone: string
constructor(type: string, phone: string, message: string) {
super(`Text Error: ${type}: ${message}`)
super(`Text Error: ${message}`)
this.phone = phone
this.context = { phone, type }
Error.captureStackTrace(this, TextError)
}
}
Expand Down
7 changes: 6 additions & 1 deletion apps/platform/src/providers/text/TextJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { loadSendJob, messageLock, notifyJourney, prepareSend } from '../Message
import { loadTextChannel } from '.'
import { releaseLock } from '../../config/scheduler'
import App from '../../app'
import { UnsubscribeTextError } from './TextError'

export default class TextJob extends Job {
static $name = 'text'
Expand Down Expand Up @@ -52,7 +53,11 @@ export default class TextJob extends Job {
user_step_id: trigger.user_step_id,
state: 'failed',
})
App.main.error.notify(error)

// Dont bubble up unsubscribes, only fail
if (!(error instanceof UnsubscribeTextError)) {
App.main.error.notify(error)
}
return
}

Expand Down

0 comments on commit 97e5e0b

Please sign in to comment.