Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

fix(web): surface API error messages

Acho Arnold Ewin91b3f02d67fe
diff --git a/web/app/components/AppToast.vue b/web/app/components/AppToast.vue
index cc62eb09..8cdf5f83 100644
--- a/web/app/components/AppToast.vue
+++ b/web/app/components/AppToast.vue
@@ -17,6 +17,7 @@ const notificationActive = computed({
variant="tonal"
:color="notificationsStore.notification.type"
:timeout="notificationsStore.notification.timeout"
+ :z-index="10000"
>
<v-icon
v-if="notificationsStore.notification.type === 'success'"
diff --git a/web/app/pages/billing/index.vue b/web/app/pages/billing/index.vue
index c5af811e..8a22aed2 100644
--- a/web/app/pages/billing/index.vue
+++ b/web/app/pages/billing/index.vue
@@ -14,6 +14,7 @@ import type {
} from '~~/shared/types/api'
import { countries, getStateOptions } from '~/utils/countries'
+import { getApiErrorMessage } from '~/utils/api-error'
type SubscriptionPayment =
ResponsesUserSubscriptionPaymentsResponse['data'][number]
@@ -197,9 +198,12 @@ async function updateDetails() {
loading.value = true
try {
window.location.href = await billingStore.getSubscriptionUpdateLink()
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'We could not redirect you to the subscription update portal.',
+ message: getApiErrorMessage(
+ error,
+ 'We could not redirect you to the subscription update portal.',
+ ),
type: 'error',
})
loading.value = false
@@ -215,9 +219,12 @@ async function cancelPlan() {
type: 'success',
})
navigateTo('/')
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'We could not cancel your subscription.',
+ message: getApiErrorMessage(
+ error,
+ 'We could not cancel your subscription.',
+ ),
type: 'error',
})
loading.value = false
diff --git a/web/app/pages/messages/index.vue b/web/app/pages/messages/index.vue
index 3dd1a544..5b6abd53 100644
--- a/web/app/pages/messages/index.vue
+++ b/web/app/pages/messages/index.vue
@@ -6,7 +6,7 @@ import {
parsePhoneNumber,
type CountryCode,
} from 'libphonenumber-js'
-import { toApiError } from '~/utils/api-error'
+import { getApiErrorMessage, toApiError } from '~/utils/api-error'
definePageMeta({
middleware: ['auth'],
@@ -91,6 +91,11 @@ async function sendMessage() {
})
}
errors.value = newErrors
+ } else {
+ notificationsStore.addNotification({
+ message: getApiErrorMessage(err, 'Failed to send message'),
+ type: 'error',
+ })
}
} finally {
sending.value = false
diff --git a/web/app/pages/phone-api-keys/index.vue b/web/app/pages/phone-api-keys/index.vue
index df13c5a6..aded9453 100644
--- a/web/app/pages/phone-api-keys/index.vue
+++ b/web/app/pages/phone-api-keys/index.vue
@@ -4,7 +4,7 @@ import QRCode from 'qrcode'
import Pusher from 'pusher-js'
import type { Channel } from 'pusher-js'
import { ErrorMessages } from '~/utils/errors'
-import { toApiError } from '~/utils/api-error'
+import { getApiErrorMessage, toApiError } from '~/utils/api-error'
import type { EntitiesPhoneAPIKey } from '~~/shared/types/api'
definePageMeta({
@@ -58,9 +58,9 @@ async function loadPhoneApiKeys() {
{ query: { limit: 100 } },
)
phoneApiKeys.value = response.data ?? []
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to load Phone API Keys',
+ message: getApiErrorMessage(error, 'Failed to load Phone API Keys'),
type: 'error',
})
} finally {
@@ -88,7 +88,7 @@ async function createPhoneApiKey() {
errorMessages.value = parseErrors(error)
if (errorMessages.value.size() === 0) {
notificationsStore.addNotification({
- message: 'Failed to create Phone API Key',
+ message: getApiErrorMessage(error, 'Failed to create Phone API Key'),
type: 'error',
})
}
@@ -155,9 +155,9 @@ async function deleteApiKey() {
})
deleteApiKeyDialog.value = false
await loadPhoneApiKeys()
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to delete Phone API Key',
+ message: getApiErrorMessage(error, 'Failed to delete Phone API Key'),
type: 'error',
})
loading.value = false
@@ -191,9 +191,12 @@ async function removePhoneFromPhoneKey() {
})
removePhoneFromApiKeyDialog.value = false
await loadPhoneApiKeys()
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to remove the phone from the Phone API Key',
+ message: getApiErrorMessage(
+ error,
+ 'Failed to remove the phone from the Phone API Key',
+ ),
type: 'error',
})
loading.value = false
diff --git a/web/app/pages/search-messages/index.vue b/web/app/pages/search-messages/index.vue
index 0e5419f7..324131b7 100644
--- a/web/app/pages/search-messages/index.vue
+++ b/web/app/pages/search-messages/index.vue
@@ -16,7 +16,7 @@ import {
import type { EntitiesMessage, EntitiesPhone } from '~~/shared/types/api'
import type { SearchMessagesRequest } from '~~/shared/types/message'
import { ErrorMessages } from '~/utils/errors'
-import { toApiError } from '~/utils/api-error'
+import { getApiErrorMessage, toApiError } from '~/utils/api-error'
interface Turnstile {
ready(callback: () => void): void
@@ -261,9 +261,12 @@ async function deleteMessages() {
type: 'success',
})
selectedIds.value = []
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Error while deleting the selected messages',
+ message: getApiErrorMessage(
+ error,
+ 'Error while deleting the selected messages',
+ ),
type: 'error',
})
} finally {
@@ -300,8 +303,15 @@ async function resendMessages() {
})
selectedIds.value = []
} else if (failed.length === results.length) {
+ const firstFailure = failed[0]
notificationsStore.addNotification({
- message: 'Error while resending the selected messages',
+ message:
+ firstFailure?.status === 'rejected'
+ ? getApiErrorMessage(
+ firstFailure.reason,
+ 'Error while resending the selected messages',
+ )
+ : 'Error while resending the selected messages',
type: 'error',
})
} else {
diff --git a/web/app/pages/settings/index.vue b/web/app/pages/settings/index.vue
index 63a8c297..f4c31203 100644
--- a/web/app/pages/settings/index.vue
+++ b/web/app/pages/settings/index.vue
@@ -23,7 +23,7 @@ import {
} from 'firebase/auth'
import QRCode from 'qrcode'
import { ErrorMessages } from '~/utils/errors'
-import { toApiError } from '~/utils/api-error'
+import { getApiErrorMessage, toApiError } from '~/utils/api-error'
import type {
EntitiesPhone,
EntitiesWebhook,
@@ -157,9 +157,9 @@ async function rotateApiKey() {
message: 'API Key rotated successfully',
type: 'success',
})
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to rotate API Key',
+ message: getApiErrorMessage(error, 'Failed to rotate API Key'),
type: 'error',
})
} finally {
@@ -198,9 +198,9 @@ async function updateTimezone(timezone: string) {
message: 'Timezone updated successfully',
type: 'success',
})
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to update timezone',
+ message: getApiErrorMessage(error, 'Failed to update timezone'),
type: 'error',
})
}
@@ -298,7 +298,7 @@ async function saveWebhook() {
errorMessages.value = parseErrors(error)
if (errorMessages.value.size() === 0) {
notificationsStore.addNotification({
- message: 'Failed to save webhook',
+ message: getApiErrorMessage(error, 'Failed to save webhook'),
type: 'error',
})
}
@@ -317,9 +317,9 @@ async function deleteWebhook(id: string) {
})
showWebhookEdit.value = false
await loadWebhooks()
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to delete webhook',
+ message: getApiErrorMessage(error, 'Failed to delete webhook'),
type: 'error',
})
} finally {
@@ -406,7 +406,10 @@ async function saveDiscord() {
errorMessages.value = parseErrors(error)
if (errorMessages.value.size() === 0) {
notificationsStore.addNotification({
- message: 'Failed to save discord integration',
+ message: getApiErrorMessage(
+ error,
+ 'Failed to save discord integration',
+ ),
type: 'error',
})
}
@@ -425,9 +428,12 @@ async function deleteDiscord(id: string) {
})
showDiscordEdit.value = false
await loadDiscordIntegrations()
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to delete discord integration',
+ message: getApiErrorMessage(
+ error,
+ 'Failed to delete discord integration',
+ ),
type: 'error',
})
} finally {
@@ -472,9 +478,9 @@ async function deletePhone(phoneId: string) {
})
showPhoneEdit.value = false
activePhone.value = null
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to delete phone',
+ message: getApiErrorMessage(error, 'Failed to delete phone'),
type: 'error',
})
} finally {
@@ -675,10 +681,10 @@ async function saveSchedule() {
await loadSendSchedules()
} catch (error: unknown) {
errorMessages.value = parseErrors(error)
- if (errorMessages.value.size() != 0) {
+ if (errorMessages.value.size() === 0) {
notificationsStore.addNotification({
type: 'error',
- message: 'Failed to save send schedule',
+ message: getApiErrorMessage(error, 'Failed to save send schedule'),
})
}
} finally {
@@ -702,10 +708,10 @@ async function deleteSchedule() {
showScheduleDelete.value = false
showScheduleEdit.value = false
await loadSendSchedules()
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
type: 'error',
- message: 'Failed to delete send schedule',
+ message: getApiErrorMessage(error, 'Failed to delete send schedule'),
})
} finally {
savingSchedule.value = false
@@ -746,9 +752,9 @@ async function saveEmailNotifications() {
type: 'success',
})
syncEmailNotifications()
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message: 'Failed to save email notifications',
+ message: getApiErrorMessage(error, 'Failed to save email notifications'),
type: 'error',
})
} finally {
@@ -780,10 +786,12 @@ async function deleteUserAccount() {
message: 'You have successfully logged out',
})
await router.push({ name: 'index' })
- } catch {
+ } catch (error: unknown) {
notificationsStore.addNotification({
- message:
- 'We ran into an internal error while deleteing your account please contact us.',
+ message: getApiErrorMessage(
+ error,
+ 'We ran into an internal error while deleting your account. Please contact us.',
+ ),
type: 'error',
})
} finally {