11import type {
22 CustomLineItemReturnItem ,
3+ InvalidInputError ,
34 LineItemReturnItem ,
45 Order ,
56 OrderAddParcelToDeliveryAction ,
@@ -29,6 +30,7 @@ import type {
2930 Store ,
3031 SyncInfo ,
3132} from "@commercetools/platform-sdk" ;
33+ import { CommercetoolsError } from "~src/exceptions" ;
3234import { getBaseResourceProperties } from "~src/helpers" ;
3335import type { Writable } from "~src/types" ;
3436import type { RepositoryContext , UpdateHandlerInterface } from "../abstract" ;
@@ -78,11 +80,29 @@ export class OrderUpdateHandler
7880 } : OrderAddParcelToDeliveryAction ,
7981 ) {
8082 if ( ! resource . shippingInfo ) {
81- throw new Error ( "Order has no shipping info" ) ;
83+ throw new CommercetoolsError < InvalidInputError > ( {
84+ code : "InvalidInput" ,
85+ message : "Order has no shipping info" ,
86+ errors : [
87+ {
88+ code : "InvalidInput" ,
89+ message : "Order has no shipping info" ,
90+ } ,
91+ ] ,
92+ } ) ;
8293 }
8394
8495 if ( ! deliveryId && ! deliveryKey ) {
85- throw new Error ( "Either deliveryId or deliveryKey must be provided" ) ;
96+ throw new CommercetoolsError < InvalidInputError > ( {
97+ code : "InvalidInput" ,
98+ message : "Either deliveryId or deliveryKey must be provided" ,
99+ errors : [
100+ {
101+ code : "InvalidInput" ,
102+ message : "Either deliveryId or deliveryKey must be provided" ,
103+ } ,
104+ ] ,
105+ } ) ;
86106 }
87107
88108 // Find the delivery by id or key
@@ -99,9 +119,17 @@ export class OrderUpdateHandler
99119
100120 if ( ! targetDelivery ) {
101121 const identifier = deliveryId || deliveryKey ;
102- throw new Error (
103- `Delivery with ${ deliveryId ? "id" : "key" } '${ identifier } ' not found` ,
104- ) ;
122+ const message = `Delivery with ${ deliveryId ? "id" : "key" } '${ identifier } ' not found` ;
123+ throw new CommercetoolsError < InvalidInputError > ( {
124+ code : "InvalidInput" ,
125+ message,
126+ errors : [
127+ {
128+ code : "InvalidInput" ,
129+ message,
130+ } ,
131+ ] ,
132+ } ) ;
105133 }
106134
107135 // Create the new parcel
0 commit comments