Skip to content

Commit 426c4eb

Browse files
committed
some adjusts
1 parent e8d5fcb commit 426c4eb

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

components/help_scout/actions/create-customer/create-customer.mjs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -153,51 +153,53 @@ export default {
153153
},
154154
},
155155
async run({ $ }) {
156-
try {
157-
const address = cleanObject({
158-
city: this.addressCity,
159-
state: this.addressState,
160-
postalCode: this.addressPostalCode,
161-
country: this.addressCountry,
162-
lines: parseObject(this.addressLines),
163-
properties: parseObject(this.properties),
164-
});
156+
const address = cleanObject({
157+
city: this.addressCity,
158+
state: this.addressState,
159+
postalCode: this.addressPostalCode,
160+
country: this.addressCountry,
161+
lines: parseObject(this.addressLines),
162+
properties: parseObject(this.properties),
163+
});
165164

166-
const data = cleanObject({
167-
firstName: this.firstName,
168-
lastName: this.lastName,
169-
phone: this.phone,
170-
photoUrl: this.photoUrl,
171-
jobTitle: this.jobTitle,
172-
photoType: this.photoType,
173-
background: this.background,
174-
location: this.location,
175-
organization: this.organization,
176-
gender: this.gender,
177-
age: this.age,
178-
emails: parseObject(this.emails),
179-
phones: parseObject(this.phones),
180-
chats: parseObject(this.chats),
181-
socialProfiles: parseObject(this.socialProfiles),
182-
websites: parseObject(this.websites),
183-
});
165+
let data = {};
184166

185-
if (Object.keys(address).length) data.address = address;
167+
data = cleanObject({
168+
firstName: this.firstName,
169+
lastName: this.lastName,
170+
phone: this.phone,
171+
photoUrl: this.photoUrl,
172+
jobTitle: this.jobTitle,
173+
photoType: this.photoType,
174+
background: this.background,
175+
location: this.location,
176+
organization: this.organization,
177+
gender: this.gender,
178+
age: this.age,
179+
emails: parseObject(this.emails),
180+
phones: parseObject(this.phones),
181+
chats: parseObject(this.chats),
182+
socialProfiles: parseObject(this.socialProfiles),
183+
websites: parseObject(this.websites),
184+
});
186185

187-
if (!Object.keys(data).length) {
188-
throw new ConfigurationError("At least one field or customer entry must be defined.");
189-
}
186+
if (Object.keys(address).length) data.address = address;
190187

188+
if (!Object.keys(data).length) {
189+
throw new ConfigurationError("At least one field or customer entry must be defined.");
190+
}
191+
192+
try {
191193
const response = await this.helpScout.createCustomer({
192194
$,
193195
data,
194196
});
195197

196198
$.export("$summary", "Successfully created the new customer.");
197199
return response;
198-
199-
} catch ({ response }) {
200-
throw new ConfigurationError(response.data.message);
200+
} catch ({ message }) {
201+
const error = JSON.parse(message)._embedded.errors[0];
202+
throw new ConfigurationError(`Path: ${error.path} - ${error.message}`);
201203
}
202204
},
203205
};

0 commit comments

Comments
 (0)