Skip to content

Commit 8d0812b

Browse files
authored
fix(query): deduplicate error response types (#2471)
1 parent 3592bae commit 8d0812b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

packages/query/src/client.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,22 +341,37 @@ export const getHookOptions = ({
341341
return value;
342342
};
343343

344+
// Helper to deduplicate union type string: "A | B | B" -> "A | B"
345+
const dedupeUnionTypes = (types: string): string => {
346+
if (!types) return types;
347+
// Split by '|', trim spaces, filter out empty, and dedupe using a Set
348+
const unique = [
349+
...new Set(
350+
types
351+
.split('|')
352+
.map((t) => t.trim())
353+
.filter(Boolean),
354+
),
355+
];
356+
return unique.join(' | ');
357+
};
358+
344359
export const getQueryErrorType = (
345360
operationName: string,
346361
response: GetterResponse,
347362
httpClient: OutputHttpClient,
348363
mutator?: GeneratorMutator,
349364
) => {
365+
const errorsType = dedupeUnionTypes(response.definition.errors || 'unknown');
366+
350367
if (mutator) {
351368
return mutator.hasErrorType
352-
? `${mutator.default ? pascal(operationName) : ''}ErrorType<${
353-
response.definition.errors || 'unknown'
354-
}>`
355-
: response.definition.errors || 'unknown';
369+
? `${mutator.default ? pascal(operationName) : ''}ErrorType<${errorsType}>`
370+
: errorsType;
356371
} else {
357372
return httpClient === OutputHttpClient.AXIOS
358-
? `AxiosError<${response.definition.errors || 'unknown'}>`
359-
: response.definition.errors || 'unknown';
373+
? `AxiosError<${errorsType}>`
374+
: errorsType;
360375
}
361376
};
362377

0 commit comments

Comments
 (0)