Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

Improve Apollo error typing (#5664)

authored by yoginth.com and committed by

GitHub 6bf9b05a 7fceab84

+39 -15
+2 -1
apps/web/src/components/Settings/Funds/Unwrap.tsx
··· 4 4 import useTransactionLifecycle from "@/hooks/useTransactionLifecycle"; 5 5 import { NATIVE_TOKEN_SYMBOL } from "@hey/data/constants"; 6 6 import { useUnwrapTokensMutation } from "@hey/indexer"; 7 + import type { ApolloClientError } from "@hey/types/errors"; 7 8 import { useState } from "react"; 8 9 import { toast } from "sonner"; 9 10 ··· 28 29 }); 29 30 }; 30 31 31 - const onError = (error: any) => { 32 + const onError = (error: ApolloClientError) => { 32 33 setIsSubmitting(false); 33 34 errorToast(error); 34 35 };
+2 -1
apps/web/src/components/Settings/Funds/Withdraw.tsx
··· 3 3 import usePollTransactionStatus from "@/hooks/usePollTransactionStatus"; 4 4 import useTransactionLifecycle from "@/hooks/useTransactionLifecycle"; 5 5 import { useWithdrawMutation } from "@hey/indexer"; 6 + import type { ApolloClientError } from "@hey/types/errors"; 6 7 import { useState } from "react"; 7 8 import { toast } from "sonner"; 8 9 import type { Address } from "viem"; ··· 29 30 }); 30 31 }; 31 32 32 - const onError = (error: any) => { 33 + const onError = (error: ApolloClientError) => { 33 34 setIsSubmitting(false); 34 35 errorToast(error); 35 36 };
+2 -1
apps/web/src/components/Settings/Funds/Wrap.tsx
··· 4 4 import useTransactionLifecycle from "@/hooks/useTransactionLifecycle"; 5 5 import { WRAPPED_NATIVE_TOKEN_SYMBOL } from "@hey/data/constants"; 6 6 import { useWrapTokensMutation } from "@hey/indexer"; 7 + import type { ApolloClientError } from "@hey/types/errors"; 7 8 import { useState } from "react"; 8 9 import { toast } from "sonner"; 9 10 ··· 28 29 }); 29 30 }; 30 31 31 - const onError = (error: any) => { 32 + const onError = (error: ApolloClientError) => { 32 33 setIsSubmitting(false); 33 34 errorToast(error); 34 35 };
+2 -1
apps/web/src/components/Settings/Manager/AccountManager/Managers/Permission.tsx
··· 8 8 type AccountManagerFragment, 9 9 useUpdateAccountManagerMutation 10 10 } from "@hey/indexer"; 11 + import type { ApolloClientError } from "@hey/types/errors"; 11 12 import { useState } from "react"; 12 13 13 14 interface PermissionProps { ··· 41 42 setIsSubmitting(false); 42 43 }; 43 44 44 - const onError = (error: any) => { 45 + const onError = (error: ApolloClientError) => { 45 46 setIsSubmitting(false); 46 47 errorToast(error); 47 48 };
+2 -1
apps/web/src/components/Shared/Account/Follow.tsx
··· 5 5 import { useAccountStore } from "@/store/persisted/useAccountStore"; 6 6 import { useApolloClient } from "@apollo/client"; 7 7 import { type AccountFragment, useFollowMutation } from "@hey/indexer"; 8 + import type { ApolloClientError } from "@hey/types/errors"; 8 9 import { useState } from "react"; 9 10 10 11 interface FollowProps { ··· 45 46 onFollow?.(); 46 47 }; 47 48 48 - const onError = (error: any) => { 49 + const onError = (error: ApolloClientError) => { 49 50 setIsSubmitting(false); 50 51 errorToast(error); 51 52 };
+2 -1
apps/web/src/components/Shared/Account/TopUp/Transfer.tsx
··· 9 9 } from "@/store/non-persisted/modal/useFundModalStore"; 10 10 import { NATIVE_TOKEN_SYMBOL } from "@hey/data/constants"; 11 11 import { useDepositMutation } from "@hey/indexer"; 12 + import type { ApolloClientError } from "@hey/types/errors"; 12 13 import { type ChangeEvent, type RefObject, useRef, useState } from "react"; 13 14 import { toast } from "sonner"; 14 15 import { formatUnits } from "viem"; ··· 46 47 }); 47 48 }; 48 49 49 - const onError = (error: any) => { 50 + const onError = (error: ApolloClientError) => { 50 51 setIsSubmitting(false); 51 52 errorToast(error); 52 53 };
+2 -1
apps/web/src/components/Shared/Account/Unfollow.tsx
··· 5 5 import { useAccountStore } from "@/store/persisted/useAccountStore"; 6 6 import { useApolloClient } from "@apollo/client"; 7 7 import { type AccountFragment, useUnfollowMutation } from "@hey/indexer"; 8 + import type { ApolloClientError } from "@hey/types/errors"; 8 9 import { useState } from "react"; 9 10 10 11 interface UnfollowProps { ··· 42 43 setIsSubmitting(false); 43 44 }; 44 45 45 - const onError = (error: any) => { 46 + const onError = (error: ApolloClientError) => { 46 47 setIsSubmitting(false); 47 48 errorToast(error); 48 49 };
+2 -1
apps/web/src/components/Shared/Audio/CoverImage.tsx
··· 6 6 import { TRANSFORMS } from "@hey/data/constants"; 7 7 import imageKit from "@hey/helpers/imageKit"; 8 8 import sanitizeDStorageUrl from "@hey/helpers/sanitizeDStorageUrl"; 9 + import type { ApolloClientError } from "@hey/types/errors"; 9 10 import type { ChangeEvent, Ref } from "react"; 10 11 import { useState } from "react"; 11 12 ··· 24 25 }: CoverImageProps) => { 25 26 const [isSubmitting, setIsSubmitting] = useState(false); 26 27 27 - const onError = (error: any) => { 28 + const onError = (error: ApolloClientError) => { 28 29 setIsSubmitting(false); 29 30 errorToast(error); 30 31 };
+2 -1
apps/web/src/components/Shared/Auth/Signup/Success.tsx
··· 4 4 import { STATIC_IMAGES_URL } from "@hey/data/constants"; 5 5 import { Errors } from "@hey/data/errors"; 6 6 import { useSwitchAccountMutation } from "@hey/indexer"; 7 + import type { ApolloClientError } from "@hey/types/errors"; 7 8 import { useEffect } from "react"; 8 9 import { useSignupStore } from "."; 9 10 10 11 const Success = () => { 11 12 const { accountAddress, onboardingToken } = useSignupStore(); 12 13 13 - const onError = (error: any) => { 14 + const onError = (error: ApolloClientError) => { 14 15 errorToast(error); 15 16 }; 16 17
+2 -1
apps/web/src/components/Shared/AvatarUpload.tsx
··· 8 8 import { Errors } from "@hey/data/errors"; 9 9 import imageKit from "@hey/helpers/imageKit"; 10 10 import sanitizeDStorageUrl from "@hey/helpers/sanitizeDStorageUrl"; 11 + import type { ApolloClientError } from "@hey/types/errors"; 11 12 import type { ChangeEvent, SyntheticEvent } from "react"; 12 13 import { useState } from "react"; 13 14 import Cropper, { type Area } from "react-easy-crop"; ··· 29 30 const [crop, setCrop] = useState({ x: 0, y: 0 }); 30 31 const [zoom, setZoom] = useState(1); 31 32 32 - const onError = (error: any) => { 33 + const onError = (error: ApolloClientError) => { 33 34 setIsSubmitting(false); 34 35 errorToast(error); 35 36 };
+2 -1
apps/web/src/components/Shared/CoverUpload.tsx
··· 8 8 import { Errors } from "@hey/data/errors"; 9 9 import imageKit from "@hey/helpers/imageKit"; 10 10 import sanitizeDStorageUrl from "@hey/helpers/sanitizeDStorageUrl"; 11 + import type { ApolloClientError } from "@hey/types/errors"; 11 12 import type { ChangeEvent, SyntheticEvent } from "react"; 12 13 import { useState } from "react"; 13 14 import Cropper, { type Area } from "react-easy-crop"; ··· 28 29 const [crop, setCrop] = useState({ x: 0, y: 0 }); 29 30 const [zoom, setZoom] = useState(1); 30 31 31 - const onError = (error: any) => { 32 + const onError = (error: ApolloClientError) => { 32 33 setIsSubmitting(false); 33 34 errorToast(error); 34 35 };
+2 -1
apps/web/src/components/Shared/Group/CancelGroupMembershipRequest.tsx
··· 6 6 type GroupFragment, 7 7 useCancelGroupMembershipRequestMutation 8 8 } from "@hey/indexer"; 9 + import type { ApolloClientError } from "@hey/types/errors"; 9 10 import { useState } from "react"; 10 11 import { toast } from "sonner"; 11 12 ··· 39 40 toast.success("Request cancelled"); 40 41 }; 41 42 42 - const onError = (error: any) => { 43 + const onError = (error: ApolloClientError) => { 43 44 setIsSubmitting(false); 44 45 errorToast(error); 45 46 };
+2 -1
apps/web/src/components/Shared/Group/Join.tsx
··· 7 7 useJoinGroupMutation, 8 8 useRequestGroupMembershipMutation 9 9 } from "@hey/indexer"; 10 + import type { ApolloClientError } from "@hey/types/errors"; 10 11 import { useState } from "react"; 11 12 import { toast } from "sonner"; 12 13 ··· 51 52 ); 52 53 }; 53 54 54 - const onError = (error: any) => { 55 + const onError = (error: ApolloClientError) => { 55 56 setIsSubmitting(false); 56 57 errorToast(error); 57 58 };
+2 -1
apps/web/src/components/Shared/Group/Leave.tsx
··· 3 3 import useTransactionLifecycle from "@/hooks/useTransactionLifecycle"; 4 4 import { useApolloClient } from "@apollo/client"; 5 5 import { type GroupFragment, useLeaveGroupMutation } from "@hey/indexer"; 6 + import type { ApolloClientError } from "@hey/types/errors"; 6 7 import { useState } from "react"; 7 8 import { toast } from "sonner"; 8 9 ··· 33 34 toast.success("Left group"); 34 35 }; 35 36 36 - const onError = (error: any) => { 37 + const onError = (error: ApolloClientError) => { 37 38 setIsSubmitting(false); 38 39 errorToast(error); 39 40 };
+2 -1
apps/web/src/hooks/useTransactionLifecycle.tsx
··· 1 1 import { Errors } from "@hey/data/errors"; 2 2 import selfFundedTransactionData from "@hey/helpers/selfFundedTransactionData"; 3 3 import sponsoredTransactionData from "@hey/helpers/sponsoredTransactionData"; 4 + import type { ApolloClientError } from "@hey/types/errors"; 4 5 import { sendEip712Transaction, sendTransaction } from "viem/zksync"; 5 6 import { useWalletClient } from "wagmi"; 6 7 import useHandleWrongNetwork from "./useHandleWrongNetwork"; ··· 44 45 }: { 45 46 transactionData: any; 46 47 onCompleted: (hash: string) => void; 47 - onError: (error: any) => void; 48 + onError: (error: ApolloClientError) => void; 48 49 }) => { 49 50 try { 50 51 switch (transactionData.__typename) {
+9
packages/types/errors.d.ts
··· 1 + import type { ApolloError } from "@apollo/client"; 2 + import type { ServerParseError } from "@apollo/client/link/http"; 3 + import type { ServerError } from "@apollo/client/link/utils"; 4 + 5 + export type ApolloClientError = 6 + | ApolloError 7 + | ServerError 8 + | ServerParseError 9 + | Error;