mirror of
https://fast.feibisi.com/https://github.com/parcelvoy/platform.git
synced 2025-08-28 11:46:02 +08:00
Improves error handling for SMS sending (#633)
This commit is contained in:
parent
4d1d7d1e53
commit
0540af3ca9
3 changed files with 10 additions and 10 deletions
|
@ -79,14 +79,14 @@ export default class TelnyxTextProvider extends TextProvider {
|
|||
|
||||
// https://support.telnyx.com/en/articles/6505121-telnyx-messaging-error-codes
|
||||
const error = responseBody.errors?.[0]
|
||||
if (error.code === 40300) {
|
||||
if (error?.code === 40300) {
|
||||
// Unable to send because recipient has unsubscribed
|
||||
throw new UnsubscribeTextError(this.type, this.phone_number, responseBody.message)
|
||||
} else if (responseBody.code === 40008) {
|
||||
throw new UnsubscribeTextError(this.type, to, error.title)
|
||||
} else if (error?.code === 40008) {
|
||||
// Unable to send because region is not enabled
|
||||
throw new UndeliverableTextError(this.type, this.phone_number, responseBody.message)
|
||||
throw new UndeliverableTextError(this.type, to, error.title)
|
||||
}
|
||||
throw new TextError(this.type, this.phone_number, responseBody.message)
|
||||
throw new TextError(this.type, to, error?.title, responseBody)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ import { ContextError } from '../../error/ErrorHandler'
|
|||
|
||||
export default class TextError extends ContextError {
|
||||
phone: string
|
||||
constructor(type: string, phone: string, message: string) {
|
||||
constructor(type: string, phone: string, message: string, context: any = {}) {
|
||||
super(`Text Error: ${message}`)
|
||||
this.phone = phone
|
||||
this.context = { phone, type }
|
||||
this.context = { phone, type, ...context }
|
||||
Error.captureStackTrace(this, TextError)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,12 +83,12 @@ export default class TwilioTextProvider extends TextProvider {
|
|||
} else {
|
||||
if (responseBody.code === 21610) {
|
||||
// Unable to send because recipient has unsubscribed
|
||||
throw new UnsubscribeTextError(this.type, this.phone_number, responseBody.message)
|
||||
throw new UnsubscribeTextError(this.type, to, responseBody.message)
|
||||
} else if (responseBody.code === 21408) {
|
||||
// Unable to send because region is not enabled
|
||||
throw new UndeliverableTextError(this.type, this.phone_number, responseBody.message)
|
||||
throw new UndeliverableTextError(this.type, to, responseBody.message)
|
||||
}
|
||||
throw new TextError(this.type, this.phone_number, responseBody.message)
|
||||
throw new TextError(this.type, to, responseBody.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue