-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix(Admin UI): Display error message when default tax zone is missing #3999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PavanendraBaahubali
wants to merge
2
commits into
vendurehq:master
Choose a base branch
from
PavanendraBaahubali:Pavan/fix-default-taxzone
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+10
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Script executed:
Repository: vendure-ecommerce/vendure
<shell_result>
Repository: vendure-ecommerce/vendure
Script execution failed with unrecoverable error: [CAPABILITY:RUN_SHELL_SCRIPT] Failed to clone repository vendure-ecommerce/vendure: Clone operation failed
</shell_result>
Script executed:
Repository: vendure-ecommerce/vendure
<shell_result>
Repository: vendure-ecommerce/vendure
Script execution failed with unrecoverable error: [CAPABILITY:RUN_SHELL_SCRIPT] Failed to clone repository vendure-ecommerce/vendure: Clone operation failed
</shell_result>
GraphQL error handling fieldErrors vs graphQLErrors structure best practices
<web_search_result>
Short answer — follow "errors-as-data" for user/field validation and keep GraphQL's errors array for system/exceptional failures. Key points and best practices:
Separate concerns
Prefer schema-typed errors for recoverable/business errors
Standardize shape and codes
Preserve partial success and use client errorPolicy
Centralize mapping & logging
Practical checklist
Selected references
</web_search_result>
Apollo Client mutation error structure error.graphQLErrors error.fieldErrors
<web_search_result>
Short answer
Why you may see error.fieldErrors
How to produce fieldErrors on the server (example)
const { GraphQLError } = require('graphql');
throw new GraphQLError('Validation failed', {
extensions: { code: 'BAD_USER_INPUT', fieldErrors: { email: 'Invalid email', password: 'Too short' } }
});
This results in errors[*].extensions.fieldErrors arriving to the client. [1][2]
How to read them on the client (example)
try {
await client.mutate({ mutation: MY_MUTATION, variables });
} catch (err) {
// err is an ApolloError
err.graphQLErrors.forEach(gqlErr => {
const fieldErrors = gqlErr.extensions?.fieldErrors;
// fieldErrors might be an object like { email: 'Invalid' }
});
}
Notes
Sources
</web_search_result>
Verify the error handling uses the correct Apollo Client error structure.
The code accesses
(error as any)?.fieldErrorsdirectly on the error object, which does not match standard Apollo Client error patterns. In Apollo Client mutations, GraphQL errors arrive inerror.graphQLErrorsarray, and field-level validation details are typically nested inerror.graphQLErrors[0].extensions?.fieldErrors(if the backend places them there), not directly on the error object.Using the incorrect access pattern means:
(error as any)masks the structural mismatchThe correct pattern should inspect
error.graphQLErrorsand check theextensionsobject:Verify with the backend team which error structure is actually sent and update accordingly.
📝 Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error object here comes from awesome-graphql-client, not Apollo.
This client wraps the GraphQL errors array into a fieldErrors property on the thrown error.
There is no graphQLErrors field in this context, which is why accessing it returned undefined during testing.
I’ve kept the fieldErrors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 48907
🌐 Web query:
💡 Result:
Short answer: GraphQLRequestError.fieldErrors is an array of GraphQL-formatted error objects (GraphQLFieldError[]). Each entry corresponds to an item from the server's response.errors and uses the standard GraphQL error shape — at minimum message, and usually locations, path and extensions when the server provides them. See the package docs and the GraphQL error format. [1][2]
Sources
@PavanendraBaahubali, thank you for the clarification! You're absolutely right. I apologize for the confusion in my previous comment.
I've confirmed that
awesome-graphql-clientthrows errors with afieldErrorsproperty that contains an array of GraphQL error objects (each withmessage,locations,path, andextensions). Your implementation is correct for this client:This properly extracts the error message from the first field error and falls back to a generic message if unavailable. The error handling should now correctly display the "The active tax zone could not be determined" message to users when the defaultTaxZone is NULL.
🧬 Code Graph Analysis Results
Snippet 1: Error handling block that extracts fieldErrors from the thrown error and reports via toast
Content:
async function handleCreateVariants() {
...
} catch (error) {
console.error('Error creating variants:', error);
}
Notes: This directly aligns with the user comment about fieldErrors being the wrapped error structure from awesome-graphql-client rather than graphQLErrors.
Snippet 2: Mutation usage context relevant to error handling (demonstrates how mutations are executed and where errors would surface)
const createOptionGroupMutation = useMutation({
mutationFn: api.mutate(createProductOptionGroupDocument),
});
const addOptionGroupToProductMutation = useMutation({
mutationFn: api.mutate(addOptionGroupToProductDocument),
});
const createProductVariantsMutation = useMutation({
mutationFn: api.mutate(createProductVariantsDocument),
});
Snippet 3: Related GraphQL documents for context (optional for understanding shape of mutations that could produce fieldErrors)
export const createProductOptionGroupDocument = graphql(
mutation CreateOptionGroups($input: CreateProductOptionGroupInput!) { createProductOptionGroup(input: $input) { id name code options { id code name } } });export const addOptionGroupToProductDocument = graphql(
mutation AddOptionGroupToProduct($productId: ID!, $optionGroupId: ID!) { addOptionGroupToProduct(productId: $productId, optionGroupId: $optionGroupId) { id optionGroups { id code name options { id code name } } } });export const createProductVariantsDocument = graphql(
mutation CreateProductVariants($input: [CreateProductVariantInput!]!) { createProductVariants(input: $input) { id name } });Snippet 4: (If helpful) useMutation hook usage context from nearby code (for understanding how errors are surfaced via the hook)
export function useMutation<T, V extends Record<string, any> = Record<string, any>>(
mutation: DocumentNode | TypedDocumentNode<T, V>,
) {
const { data, loading, error, runQuery } = useDataService<T, V>((dataService, variables) =>
dataService.mutate(mutation, variables),
);
const rest = { data, loading, error };
const execute = (variables?: V) => firstValueFrom(runQuery(variables));
return [execute, rest] as [typeof execute, typeof rest];
}
✏️ Learnings added