Skip to content

Commit

Permalink
Gracefull handler
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejewsky committed Nov 15, 2024
1 parent d6aa7fa commit a77cb57
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-knives-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Variant creation no longer reports an error when API call fails, this means this scenario is now handled gracefully.
4 changes: 4 additions & 0 deletions locale/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,10 @@
"DGCzal": {
"string": "This token gives you access to your shop's API, which you'll find here: {url}"
},
"DGWVA9": {
"context": "variant created error message",
"string": "Variant creation failed"
},
"DHBlFi": {
"context": "navigator customer mode description",
"string": "Search Customers"
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/makeMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function useMutation<TData, TVariables>(
},
onError: (err: ApolloError) => {
if (!disableErrorHandling) {
if (err?.graphQLErrors.length > 0) {
if (err?.graphQLErrors?.length > 0) {
if (hasError(err, GqlErrors.ReadOnlyException)) {
notify({
status: "error",
Expand Down
17 changes: 16 additions & 1 deletion src/products/views/ProductVariantCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({ productId,
onCompleted: data => {
const variantId = data.productVariantCreate.productVariant.id;

if (!variantId) {
notify({
status: "error",
text: intl.formatMessage(messages.variantCreatedError),
});

return;
}

notify({
status: "success",
text: intl.formatMessage(messages.variantCreatedSuccess),
Expand All @@ -98,6 +107,7 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({ productId,
formData.attributesWithNewFileValue,
uploadFilesResult,
);

const variantCreateResult = await variantCreate({
variables: {
input: {
Expand Down Expand Up @@ -136,7 +146,12 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({ productId,
return { id: null, errors: variantCreateResultErrors };
}

const id = variantCreateResult.data.productVariantCreate.productVariant.id;
const id = variantCreateResult.data?.productVariantCreate?.productVariant?.id;

if (!id) {
return { id: null, errors: [] };
}

const updateChannelsResult = await updateChannels({
variables: {
id,
Expand Down
5 changes: 5 additions & 0 deletions src/products/views/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ export const variantCreateMessages = defineMessages({
defaultMessage: "Variant created",
description: "variant created success message",
},
variantCreatedError: {
id: "DGWVA9",
defaultMessage: "Variant creation failed",
description: "variant created error message",
},
});

0 comments on commit a77cb57

Please sign in to comment.