Skip to content

Commit 75cf4fd

Browse files
authored
Merge pull request #698 from seamapi/evan/cx-416-extend-error-type-for-seam-query-hooks-to-support-action
Extend hook error types
2 parents 019e78b + 619f240 commit 75cf4fd

File tree

6 files changed

+59
-11
lines changed

6 files changed

+59
-11
lines changed

src/lib/seam/components/CreateAccessCodeForm/CreateAccessCodeForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ function useSubmitCreateAccessCode(params: {
145145

146146
export function useResponseErrors(): {
147147
responseErrors: ResponseErrors | null
148-
handleResponseError: (error: SeamHttpApiError) => void
148+
handleResponseError: (error: SeamHttpApiError | Error) => void
149149
resetResponseErrors: () => void
150150
} {
151151
const [responseErrors, setResponseErrors] = useState<Record<
152152
string,
153153
string | undefined
154154
> | null>(null)
155155

156-
const handleResponseError = (error: SeamHttpApiError): void => {
156+
const handleResponseError = (error: SeamHttpApiError | Error): void => {
157157
if (isSeamHttpInvalidInputError(error)) {
158158
const errors = shake({
159159
code: error.getValidationErrorMessages('code')[0],

src/lib/seam/use-seam-infinite-query.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import type {
2+
SeamActionAttemptFailedError,
3+
SeamActionAttemptTimeoutError,
24
SeamHttpApiError,
35
SeamHttpEndpointPaginatedQueryPaths,
46
SeamHttpEndpoints,
7+
SeamHttpInvalidInputError,
58
SeamHttpRequest,
69
SeamPageCursor,
710
} from '@seamapi/http/connect'
11+
import type { ActionAttempt } from '@seamapi/types/connect'
812
import {
913
useInfiniteQuery,
1014
type UseInfiniteQueryOptions,
@@ -19,15 +23,15 @@ export type UseSeamInfiniteQueryParameters<
1923

2024
export type UseSeamInfiniteQueryResult<
2125
T extends SeamHttpEndpointPaginatedQueryPaths,
22-
> = UseInfiniteQueryResult<QueryData<T>, SeamHttpApiError>
26+
> = UseInfiniteQueryResult<QueryData<T>, QueryError<T>>
2327

2428
export function useSeamInfiniteQuery<
2529
T extends SeamHttpEndpointPaginatedQueryPaths,
2630
>(
2731
endpointPath: T,
2832
parameters?: UseSeamInfiniteQueryParameters<T>,
2933
options: Parameters<SeamHttpEndpoints[T]>[1] &
30-
QueryOptions<QueryData<T>, SeamHttpApiError> = {}
34+
QueryOptions<QueryData<T>, QueryError<T>> = {}
3135
): UseSeamInfiniteQueryResult<T> {
3236
const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
3337
return useInfiniteQuery({
@@ -75,6 +79,16 @@ interface QueryData<T extends SeamHttpEndpointPaginatedQueryPaths> {
7579
nextPageCursor: SeamPageCursor | null
7680
}
7781

82+
type QueryError<T extends SeamHttpEndpointPaginatedQueryPaths> =
83+
| Error
84+
| SeamHttpApiError
85+
| SeamHttpInvalidInputError
86+
| (QueryData<T>['data'] extends ActionAttempt
87+
?
88+
| SeamActionAttemptFailedError<QueryData<T>['data']>
89+
| SeamActionAttemptTimeoutError<QueryData<T>['data']>
90+
: never)
91+
7892
type QueryOptions<X, Y> = Omit<
7993
UseInfiniteQueryOptions<X, Y>,
8094
'queryKey' | 'queryFn' | 'initialPageParam' | 'getNextPageParam'

src/lib/seam/use-seam-mutation-without-workspace.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
SeamHttpApiError,
33
SeamHttpEndpointsWithoutWorkspace,
44
SeamHttpEndpointWithoutWorkspaceMutationPaths,
5+
SeamHttpInvalidInputError,
56
} from '@seamapi/http/connect'
67
import {
78
useMutation,
@@ -19,7 +20,7 @@ export type UseSeamMutationWithoutWorkspaceResult<
1920
T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
2021
> = UseMutationResult<
2122
MutationData<T>,
22-
SeamHttpApiError,
23+
MutationError,
2324
UseSeamMutationWithoutWorkspaceVariables<T>
2425
>
2526

@@ -30,7 +31,7 @@ export function useSeamMutationWithoutWorkspace<
3031
options: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] &
3132
MutationOptions<
3233
MutationData<T>,
33-
SeamHttpApiError,
34+
MutationError,
3435
UseSeamMutationWithoutWorkspaceVariables<T>
3536
> = {}
3637
): UseSeamMutationWithoutWorkspaceResult<T> {
@@ -50,4 +51,6 @@ export function useSeamMutationWithoutWorkspace<
5051
type MutationData<T extends SeamHttpEndpointWithoutWorkspaceMutationPaths> =
5152
Awaited<ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>>
5253

54+
type MutationError = Error | SeamHttpApiError | SeamHttpInvalidInputError
55+
5356
type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>

src/lib/seam/use-seam-mutation.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import type {
2+
SeamActionAttemptFailedError,
3+
SeamActionAttemptTimeoutError,
24
SeamHttpApiError,
35
SeamHttpEndpointMutationPaths,
46
SeamHttpEndpoints,
7+
SeamHttpInvalidInputError,
58
} from '@seamapi/http/connect'
9+
import type { ActionAttempt } from '@seamapi/types/connect'
610
import {
711
useMutation,
812
type UseMutationOptions,
@@ -17,7 +21,7 @@ export type UseSeamMutationVariables<T extends SeamHttpEndpointMutationPaths> =
1721
export type UseSeamMutationResult<T extends SeamHttpEndpointMutationPaths> =
1822
UseMutationResult<
1923
MutationData<T>,
20-
SeamHttpApiError,
24+
MutationError<T>,
2125
UseSeamMutationVariables<T>
2226
>
2327

@@ -26,7 +30,7 @@ export function useSeamMutation<T extends SeamHttpEndpointMutationPaths>(
2630
options: Parameters<SeamHttpEndpoints[T]>[1] &
2731
MutationOptions<
2832
MutationData<T>,
29-
SeamHttpApiError,
33+
MutationError<T>,
3034
UseSeamMutationVariables<T>
3135
> = {}
3236
): UseSeamMutationResult<T> {
@@ -47,4 +51,14 @@ type MutationData<T extends SeamHttpEndpointMutationPaths> = Awaited<
4751
ReturnType<SeamHttpEndpoints[T]>
4852
>
4953

54+
type MutationError<T extends SeamHttpEndpointMutationPaths> =
55+
| Error
56+
| SeamHttpApiError
57+
| SeamHttpInvalidInputError
58+
| (MutationData<T> extends ActionAttempt
59+
?
60+
| SeamActionAttemptFailedError<MutationData<T>>
61+
| SeamActionAttemptTimeoutError<MutationData<T>>
62+
: never)
63+
5064
type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>

src/lib/seam/use-seam-query-without-workspace.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
SeamHttpApiError,
33
SeamHttpEndpointsWithoutWorkspace,
44
SeamHttpEndpointWithoutWorkspaceQueryPaths,
5+
SeamHttpInvalidInputError,
56
} from '@seamapi/http/connect'
67
import {
78
useQuery,
@@ -17,15 +18,15 @@ export type UseSeamQueryWithoutWorkspaceParameters<
1718

1819
export type UseSeamQueryWithoutWorkspaceResult<
1920
T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
20-
> = UseQueryResult<QueryData<T>, SeamHttpApiError>
21+
> = UseQueryResult<QueryData<T>, QueryError>
2122

2223
export function useSeamQueryWithoutWorkspace<
2324
T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
2425
>(
2526
endpointPath: T,
2627
parameters?: UseSeamQueryWithoutWorkspaceParameters<T>,
2728
options: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] &
28-
QueryOptions<QueryData<T>, SeamHttpApiError> = {}
29+
QueryOptions<QueryData<T>, QueryError> = {}
2930
): UseSeamQueryWithoutWorkspaceResult<T> {
3031
const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
3132
return useQuery({
@@ -50,4 +51,6 @@ type QueryData<T extends SeamHttpEndpointWithoutWorkspaceQueryPaths> = Awaited<
5051
ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>
5152
>
5253

54+
type QueryError = Error | SeamHttpApiError | SeamHttpInvalidInputError
55+
5356
type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>

src/lib/seam/use-seam-query.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import type {
2+
SeamActionAttemptFailedError,
3+
SeamActionAttemptTimeoutError,
24
SeamHttpApiError,
35
SeamHttpEndpointQueryPaths,
46
SeamHttpEndpoints,
7+
SeamHttpInvalidInputError,
58
} from '@seamapi/http/connect'
9+
import type { ActionAttempt } from '@seamapi/types/connect'
610
import {
711
useQuery,
812
type UseQueryOptions,
@@ -15,7 +19,7 @@ export type UseSeamQueryParameters<T extends SeamHttpEndpointQueryPaths> =
1519
Parameters<SeamHttpEndpoints[T]>[0]
1620

1721
export type UseSeamQueryResult<T extends SeamHttpEndpointQueryPaths> =
18-
UseQueryResult<QueryData<T>, SeamHttpApiError>
22+
UseQueryResult<QueryData<T>, QueryError<T>>
1923

2024
export function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(
2125
endpointPath: T,
@@ -46,4 +50,14 @@ type QueryData<T extends SeamHttpEndpointQueryPaths> = Awaited<
4650
ReturnType<SeamHttpEndpoints[T]>
4751
>
4852

53+
type QueryError<T extends SeamHttpEndpointQueryPaths> =
54+
| Error
55+
| SeamHttpApiError
56+
| SeamHttpInvalidInputError
57+
| (QueryData<T> extends ActionAttempt
58+
?
59+
| SeamActionAttemptFailedError<QueryData<T>>
60+
| SeamActionAttemptTimeoutError<QueryData<T>>
61+
: never)
62+
4963
type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>

0 commit comments

Comments
 (0)