Browse Source

fix(admin-ui): Handle all ErrorResults when creating a Fulfillment

Fixes #929
Michael Bromley 4 years ago
parent
commit
75952ddc58

+ 4 - 0
packages/admin-ui/src/lib/core/src/common/generated-types.ts

@@ -6027,9 +6027,11 @@ export type CreateFulfillmentMutation = { addFulfillmentToOrder: (
     & ErrorResult_InvalidFulfillmentHandlerError_Fragment
   ) | (
     { __typename?: 'FulfillmentStateTransitionError' }
+    & Pick<FulfillmentStateTransitionError, 'errorCode' | 'message' | 'transitionError'>
     & ErrorResult_FulfillmentStateTransitionError_Fragment
   ) | (
     { __typename?: 'CreateFulfillmentError' }
+    & Pick<CreateFulfillmentError, 'errorCode' | 'message' | 'fulfillmentHandlerError'>
     & ErrorResult_CreateFulfillmentError_Fragment
   ) };
 
@@ -8917,6 +8919,8 @@ export namespace CreateFulfillment {
   export type Variables = CreateFulfillmentMutationVariables;
   export type Mutation = CreateFulfillmentMutation;
   export type AddFulfillmentToOrder = (NonNullable<CreateFulfillmentMutation['addFulfillmentToOrder']>);
+  export type CreateFulfillmentErrorInlineFragment = (DiscriminateUnion<(NonNullable<CreateFulfillmentMutation['addFulfillmentToOrder']>), { __typename?: 'CreateFulfillmentError' }>);
+  export type FulfillmentStateTransitionErrorInlineFragment = (DiscriminateUnion<(NonNullable<CreateFulfillmentMutation['addFulfillmentToOrder']>), { __typename?: 'FulfillmentStateTransitionError' }>);
 }
 
 export namespace CancelOrder {

+ 10 - 0
packages/admin-ui/src/lib/core/src/data/definitions/order-definitions.ts

@@ -308,6 +308,16 @@ export const CREATE_FULFILLMENT = gql`
     mutation CreateFulfillment($input: FulfillOrderInput!) {
         addFulfillmentToOrder(input: $input) {
             ...Fulfillment
+            ... on CreateFulfillmentError {
+                errorCode
+                message
+                fulfillmentHandlerError
+            }
+            ... on FulfillmentStateTransitionError {
+                errorCode
+                message
+                transitionError
+            }
             ...ErrorResult
         }
     }

+ 16 - 2
packages/admin-ui/src/lib/order/src/components/order-detail/order-detail.component.ts

@@ -64,6 +64,7 @@ export class OrderDetailComponent
         'Modifying',
         'ArrangingAdditionalPayment',
     ];
+
     constructor(
         router: Router,
         route: ActivatedRoute,
@@ -332,15 +333,28 @@ export class OrderDetailComponent
             )
             .subscribe(result => {
                 if (result) {
-                    switch (result.addFulfillmentToOrder.__typename) {
+                    const { addFulfillmentToOrder } = result;
+                    switch (addFulfillmentToOrder.__typename) {
                         case 'Fulfillment':
                             this.notificationService.success(_('order.create-fulfillment-success'));
                             break;
                         case 'EmptyOrderLineSelectionError':
                         case 'InsufficientStockOnHandError':
                         case 'ItemsAlreadyFulfilledError':
-                            this.notificationService.error(result.addFulfillmentToOrder.message);
+                        case 'InvalidFulfillmentHandlerError':
+                            this.notificationService.error(addFulfillmentToOrder.message);
+                            break;
+                        case 'FulfillmentStateTransitionError':
+                            this.notificationService.error(addFulfillmentToOrder.transitionError);
+                            break;
+                        case 'CreateFulfillmentError':
+                            this.notificationService.error(addFulfillmentToOrder.fulfillmentHandlerError);
                             break;
+                        case undefined:
+                            this.notificationService.error(JSON.stringify(addFulfillmentToOrder));
+                            break;
+                        default:
+                            assertNever(addFulfillmentToOrder);
                     }
                 }
             });

+ 1 - 0
packages/core/src/i18n/messages/en.json

@@ -53,6 +53,7 @@
     "COUPON_CODE_EXPIRED_ERROR": "Coupon code \"{ couponCode }\" has expired",
     "COUPON_CODE_INVALID_ERROR": "Coupon code \"{ couponCode }\" is not valid",
     "COUPON_CODE_LIMIT_ERROR": "Coupon code cannot be used more than {limit, plural, one {once} other {# times}} per customer",
+    "CREATE_FULFILLMENT_ERROR": "An error occurred when attempting to create the Fulfillment",
     "EMAIL_ADDRESS_CONFLICT_ERROR": "The email address is not available.",
     "EMPTY_ORDER_LINE_SELECTION_ERROR": "At least one OrderLine must be specified",
     "IDENTIFIER_CHANGE_TOKEN_INVALID_ERROR": "Identifier change token not recognized",