Improve Hubspot error handling

This commit is contained in:
Jan Oberhauser 2020-03-29 10:17:11 +02:00
parent 7be0a0a7b3
commit a1932a5427

View file

@ -258,12 +258,8 @@ export class Hubspot implements INodeType {
});
}
body.associations = association;
try {
const endpoint = '/deals/v1/deal';
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'update') {
const body: IDeal = {};
@ -311,12 +307,8 @@ export class Hubspot implements INodeType {
value: updateFields.pipeline as string
});
}
try {
const endpoint = `/deals/v1/deal/${dealId}`;
responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, body);
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'get') {
const dealId = this.getNodeParameter('dealId', i) as string;
@ -324,12 +316,8 @@ export class Hubspot implements INodeType {
if (additionalFields.includePropertyVersions) {
qs.includePropertyVersions = additionalFields.includePropertyVersions as boolean;
}
try {
const endpoint = `/deals/v1/deal/${dealId}`;
responseData = await hubspotApiRequest.call(this, 'GET', endpoint);
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'getAll') {
const filters = this.getNodeParameter('filters', i) as IDataObject;
@ -345,7 +333,6 @@ export class Hubspot implements INodeType {
// @ts-ignore
qs.propertiesWithHistory = filters.propertiesWithHistory.split(',');
}
try {
const endpoint = `/deals/v1/deal/paged`;
if (returnAll) {
responseData = await hubspotApiRequestAllItems.call(this, 'deals', 'GET', endpoint, {}, qs);
@ -354,9 +341,6 @@ export class Hubspot implements INodeType {
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
responseData = responseData.deals;
}
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'getRecentlyCreated' || operation === 'getRecentlyModified') {
let endpoint;
@ -368,7 +352,6 @@ export class Hubspot implements INodeType {
if (filters.includePropertyVersions) {
qs.includePropertyVersions = filters.includePropertyVersions as boolean;
}
try {
if (operation === 'getRecentlyCreated') {
endpoint = `/deals/v1/deal/recent/created`;
} else {
@ -381,18 +364,11 @@ export class Hubspot implements INodeType {
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
responseData = responseData.results;
}
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'delete') {
const dealId = this.getNodeParameter('dealId', i) as string;
try {
const endpoint = `/deals/v1/deal/${dealId}`;
responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
} catch (err) {
throw new Error(`Hubspot Error: ${JSON.stringify(err)}`);
}
}
}
//https://developers.hubspot.com/docs/methods/forms/forms_overview