mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
show detailed error message in toast
This commit is contained in:
parent
40f681db2e
commit
06087c8578
2 changed files with 27 additions and 11 deletions
|
|
@ -6,9 +6,15 @@ interface UpdateSubscriptionResult {
|
|||
updateSubscription: UpdateSubscription
|
||||
}
|
||||
|
||||
export enum UpdateSubscriptionErrorCode {
|
||||
BAD_REQUEST = 'BAD_REQUEST',
|
||||
NOT_FOUND = 'NOT_FOUND',
|
||||
UNAUTHORIZED = 'UNAUTHORIZED',
|
||||
}
|
||||
|
||||
interface UpdateSubscription {
|
||||
subscription: Subscription
|
||||
errorCodes?: unknown[]
|
||||
subscription?: Subscription
|
||||
errorCodes?: UpdateSubscriptionErrorCode[]
|
||||
}
|
||||
|
||||
interface UpdateSubscriptionInput {
|
||||
|
|
@ -20,7 +26,7 @@ interface UpdateSubscriptionInput {
|
|||
|
||||
export async function updateSubscriptionMutation(
|
||||
input: UpdateSubscriptionInput
|
||||
): Promise<any | undefined> {
|
||||
): Promise<UpdateSubscriptionResult> {
|
||||
const mutation = gql`
|
||||
mutation UpdateSubscription($input: UpdateSubscriptionInput!) {
|
||||
updateSubscription(input: $input) {
|
||||
|
|
@ -41,11 +47,13 @@ export async function updateSubscriptionMutation(
|
|||
const data = (await gqlFetcher(mutation, {
|
||||
input,
|
||||
})) as UpdateSubscriptionResult
|
||||
return data.updateSubscription.errorCodes
|
||||
? undefined
|
||||
: data.updateSubscription.subscription.id
|
||||
return data
|
||||
} catch (error) {
|
||||
console.log('updateSubscriptionMutation error', error)
|
||||
return undefined
|
||||
return {
|
||||
updateSubscription: {
|
||||
errorCodes: [UpdateSubscriptionErrorCode.BAD_REQUEST],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import {
|
|||
} from '../../../lib/networking/queries/useGetSubscriptionsQuery'
|
||||
import { applyStoredTheme } from '../../../lib/themeUpdater'
|
||||
import { showErrorToast, showSuccessToast } from '../../../lib/toastHelpers'
|
||||
import { formatMessage } from '../../../locales/en/messages'
|
||||
|
||||
export default function Rss(): JSX.Element {
|
||||
const router = useRouter()
|
||||
|
|
@ -35,12 +36,18 @@ export default function Rss(): JSX.Element {
|
|||
id: onEditId,
|
||||
name: onEditName,
|
||||
})
|
||||
if (result) {
|
||||
showSuccessToast('RSS feed updated', { position: 'bottom-right' })
|
||||
} else {
|
||||
showErrorToast('Failed to update', { position: 'bottom-right' })
|
||||
|
||||
if (result.updateSubscription.errorCodes) {
|
||||
const errorMessage = formatMessage({
|
||||
id: `error.${result.updateSubscription.errorCodes[0]}`,
|
||||
})
|
||||
showErrorToast(`failed to update subscription: ${errorMessage}`, {
|
||||
position: 'bottom-right',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
showSuccessToast('RSS feed updated', { position: 'bottom-right' })
|
||||
revalidate()
|
||||
}
|
||||
|
||||
|
|
@ -109,6 +116,7 @@ export default function Rss(): JSX.Element {
|
|||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
setOnEditId('')
|
||||
setOnEditName('')
|
||||
}}
|
||||
/>
|
||||
</HStack>
|
||||
|
|
|
|||
Loading…
Reference in a new issue