diff --git a/src/app/components/image-pack-view/RoomImagePack.tsx b/src/app/components/image-pack-view/RoomImagePack.tsx index 6b10781c..b52bb103 100644 --- a/src/app/components/image-pack-view/RoomImagePack.tsx +++ b/src/app/components/image-pack-view/RoomImagePack.tsx @@ -1,5 +1,6 @@ import React, { useCallback, useMemo } from 'react'; import { putStateEvent } from 'neurone/lib/api/matrix/client/v3/rooms'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { usePowerLevelsContext } from '../../hooks/usePowerLevels'; import { ImagePackContent } from './ImagePackContent'; import { ImagePack, PackContent } from '../../plugins/custom-emoji'; @@ -43,7 +44,7 @@ export function RoomImagePack({ roomId, stateKey }: RoomImagePackProps) { const { address } = imagePack; if (!address) return; - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( putStateEvent({ pathParams: { roomId: address.roomId, @@ -53,6 +54,8 @@ export function RoomImagePack({ roomId, stateKey }: RoomImagePackProps) { body: packContent, }) ); + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct, imagePack] ); diff --git a/src/app/components/image-pack-view/UserImagePack.tsx b/src/app/components/image-pack-view/UserImagePack.tsx index fcd93b8d..d7c7db22 100644 --- a/src/app/components/image-pack-view/UserImagePack.tsx +++ b/src/app/components/image-pack-view/UserImagePack.tsx @@ -1,5 +1,6 @@ import React, { useCallback, useMemo } from 'react'; import { putAccountData } from 'neurone/lib/api/matrix/client/v3/user'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { ImagePackContent } from './ImagePackContent'; import { ImagePack, PackContent } from '../../plugins/custom-emoji'; import { AccountDataType } from '../../../types/matrix/accountData'; @@ -15,12 +16,14 @@ export function UserImagePack() { const handleUpdate = useCallback( async (packContent: PackContent) => { - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( putAccountData({ pathParams: { type: AccountDataType.PoniesUserEmotes, userId: ct.session.userId }, body: packContent, }) ); + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct] ); diff --git a/src/app/components/invite-user-prompt/InviteUserPrompt.tsx b/src/app/components/invite-user-prompt/InviteUserPrompt.tsx index 57f54c0d..b1d38a73 100644 --- a/src/app/components/invite-user-prompt/InviteUserPrompt.tsx +++ b/src/app/components/invite-user-prompt/InviteUserPrompt.tsx @@ -31,6 +31,7 @@ import { import { isKeyHotkey } from 'is-hotkey'; import FocusTrap from 'focus-trap-react'; import { postInvite } from 'neurone/lib/api/matrix/client/v3/rooms'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { stopPropagation } from '../../utils/keyboard'; import { useDirectUsers } from '../../hooks/useDirectUsers'; import { getMxIdLocalPart, getMxIdServer, isUserId } from '../../utils/matrix'; @@ -73,7 +74,7 @@ export function InviteUserPrompt({ roomId, requestClose }: InviteUserProps) { const [inviteState, invite] = useAsyncCallback( useCallback( async (userId, reason) => { - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( postInvite({ pathParams: { roomId }, body: { @@ -82,6 +83,8 @@ export function InviteUserPrompt({ roomId, requestClose }: InviteUserProps) { }, }) ); + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct, roomId] ) diff --git a/src/app/features/common-settings/permissions/PermissionGroups.tsx b/src/app/features/common-settings/permissions/PermissionGroups.tsx index 945395db..50f51619 100644 --- a/src/app/features/common-settings/permissions/PermissionGroups.tsx +++ b/src/app/features/common-settings/permissions/PermissionGroups.tsx @@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { Badge, Box, Button, Chip, config, Icon, Icons, Menu, Spinner, Text } from 'folds'; import produce from 'immer'; import { putStateEvent } from 'neurone/lib/api/matrix/client/v3/rooms'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { SequenceCard } from '../../../components/sequence-card'; import { SequenceCardStyle } from '../styles.css'; import { SettingTile } from '../../../components/setting-tile'; @@ -86,12 +87,14 @@ export function PermissionGroups({ permissionGroups, canEdit }: PermissionGroups return draftPowerLevels; }); - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( putStateEvent({ pathParams: { roomId, eventType: StateEventType.RoomPowerLevels, stateKey: '' }, body: editedPowerLevels, }) ); + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct, roomId, powerLevels, permissionUpdate, permissionGroups]) ); diff --git a/src/app/features/common-settings/permissions/PowersEditor.tsx b/src/app/features/common-settings/permissions/PowersEditor.tsx index 19a1ff75..73097d89 100644 --- a/src/app/features/common-settings/permissions/PowersEditor.tsx +++ b/src/app/features/common-settings/permissions/PowersEditor.tsx @@ -20,6 +20,7 @@ import { } from 'folds'; import { HexColorPicker } from 'react-colorful'; import { putStateEvent } from 'neurone/lib/api/matrix/client/v3/rooms'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { Page, PageContent, PageHeader } from '../../../components/page'; import { usePowerLevelsContext } from '../../../hooks/usePowerLevels'; import { SequenceCard } from '../../../components/sequence-card'; @@ -333,12 +334,14 @@ export function PowersEditor({ requestClose }: PowersEditorProps) { deleted.forEach((power) => { delete content[power]; }); - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( putStateEvent({ pathParams: { roomId, eventType: StateEventType.PowerLevelTags, stateKey: '' }, body: content, }) ); + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct, roomId, powerLevelTags, editedPowerTags, deleted]) ); diff --git a/src/app/features/settings/notifications/AllMessages.tsx b/src/app/features/settings/notifications/AllMessages.tsx index bcf3589e..99739e68 100644 --- a/src/app/features/settings/notifications/AllMessages.tsx +++ b/src/app/features/settings/notifications/AllMessages.tsx @@ -2,6 +2,7 @@ import React, { useCallback, useMemo } from 'react'; import { Badge, Box, Text } from 'folds'; import { PushRuleCondition, PushRules } from 'neurone/lib/api/types'; import { putPushRuleActions } from 'neurone/lib/api/matrix/client/v3/pushrules'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { AccountDataType, ConditionKind, PushRuleId } from '../../../../types/matrix/accountData'; import { NotificationModeSwitcher } from './NotificationModeSwitcher'; import { SequenceCard } from '../../../components/sequence-card'; @@ -65,12 +66,14 @@ function AllMessagesModeSwitcher({ const handleChange = useCallback( async (mode: NotificationMode) => { const actions = getModeActions(mode); - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( putPushRuleActions({ pathParams: { scope: 'global', kind, ruleId }, body: { actions }, }) ); + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct, getModeActions, kind, ruleId] ); diff --git a/src/app/features/settings/notifications/KeywordMessages.tsx b/src/app/features/settings/notifications/KeywordMessages.tsx index 259736c8..ad15dfc1 100644 --- a/src/app/features/settings/notifications/KeywordMessages.tsx +++ b/src/app/features/settings/notifications/KeywordMessages.tsx @@ -5,6 +5,7 @@ import { putPushRule, putPushRuleActions, } from 'neurone/lib/api/matrix/client/v3/pushrules'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { PushRule, PushRules } from 'neurone/lib/api/types'; import { useAccountData } from '../../../hooks/storage/useAccountData'; import { AccountDataType } from '../../../../types/matrix/accountData'; @@ -32,7 +33,7 @@ function KeywordInput() { const [keywordState, addKeyword] = useAsyncCallback( useCallback( async (k: string) => { - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( putPushRule({ pathParams: { scope: 'global', kind: 'content', ruleId: k }, body: { @@ -41,6 +42,9 @@ function KeywordInput() { }, }) ); + + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); setKeyword(''); }, [ct] @@ -147,7 +151,7 @@ function KeywordModeSwitcher({ pushRule }: PushRulesProps) { const handleChange = useCallback( async (mode: NotificationMode) => { const actions = getModeActions(mode); - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( putPushRuleActions({ pathParams: { scope: 'global', kind: 'content', ruleId: pushRule.rule_id }, body: { @@ -155,6 +159,9 @@ function KeywordModeSwitcher({ pushRule }: PushRulesProps) { }, }) ); + + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct, getModeActions, pushRule] ); diff --git a/src/app/features/settings/notifications/SpecialMessages.tsx b/src/app/features/settings/notifications/SpecialMessages.tsx index edea496b..52387909 100644 --- a/src/app/features/settings/notifications/SpecialMessages.tsx +++ b/src/app/features/settings/notifications/SpecialMessages.tsx @@ -2,6 +2,7 @@ import React, { useCallback, useMemo } from 'react'; import { Box, Text, Badge } from 'folds'; import { PushRules } from 'neurone/lib/api/types'; import { putPushRuleActions } from 'neurone/lib/api/matrix/client/v3/pushrules'; +import { parseMatrixResp } from 'neurone/lib/matrix-request'; import { useAccountData } from '../../../hooks/storage/useAccountData'; import { AccountDataType, ConditionKind, PushRuleId } from '../../../../types/matrix/accountData'; import { SequenceCard } from '../../../components/sequence-card'; @@ -104,12 +105,15 @@ function MentionModeSwitcher({ ruleId, pushRules, defaultPushRuleData }: PushRul const handleChange = useCallback( async (mode: NotificationMode) => { const actions = getModeActions(mode); - await ct.requestAuthJSON( + const resp = await ct.requestAuthJSON( putPushRuleActions({ pathParams: { scope: 'global', kind, ruleId }, body: { actions }, }) ); + + const [err] = await parseMatrixResp(resp); + if (err) throw new Error(err.data.error ?? err.data.errcode); }, [ct, getModeActions, kind, ruleId] );