Skip to content

Commit

Permalink
fix(admin-ui): Handle all ErrorResults when creating a Fulfillment
Browse files Browse the repository at this point in the history
Fixes #929
  • Loading branch information
michaelbromley committed Jun 16, 2021
1 parent 33f40f2 commit 75952dd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
) };

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class OrderDetailComponent
'Modifying',
'ArrangingAdditionalPayment',
];

constructor(
router: Router,
route: ActivatedRoute,
Expand Down Expand Up @@ -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);
}
}
});
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 75952dd

Please sign in to comment.