1
1
import type {
2
2
CustomLineItemReturnItem ,
3
+ InvalidInputError ,
3
4
LineItemReturnItem ,
4
5
Order ,
5
6
OrderAddParcelToDeliveryAction ,
@@ -29,6 +30,7 @@ import type {
29
30
Store ,
30
31
SyncInfo ,
31
32
} from "@commercetools/platform-sdk" ;
33
+ import { CommercetoolsError } from "~src/exceptions" ;
32
34
import { getBaseResourceProperties } from "~src/helpers" ;
33
35
import type { Writable } from "~src/types" ;
34
36
import type { RepositoryContext , UpdateHandlerInterface } from "../abstract" ;
@@ -78,11 +80,29 @@ export class OrderUpdateHandler
78
80
} : OrderAddParcelToDeliveryAction ,
79
81
) {
80
82
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
+ } ) ;
82
93
}
83
94
84
95
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
+ } ) ;
86
106
}
87
107
88
108
// Find the delivery by id or key
@@ -99,9 +119,17 @@ export class OrderUpdateHandler
99
119
100
120
if ( ! targetDelivery ) {
101
121
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
+ } ) ;
105
133
}
106
134
107
135
// Create the new parcel
0 commit comments