Extended Hubspot functionality

This commit is contained in:
ricardo
2020-03-22 22:39:40 -04:00
parent f0f4a04c74
commit fa922d363e
4 changed files with 478 additions and 36 deletions

View File

@@ -26,17 +26,20 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions
json: true,
useQuerystring: true,
};
try {
return await this.helpers.request!(options);
} catch (error) {
const errorMessage = error.response.body.message || error.response.body.Message || error.message;
throw new Error(`Hubspot error response [${error.statusCode}]: ${errorMessage}`);
if (error.response && error.response.body && error.response.body.errors) {
// Try to return the error prettier
const errorMessages = error.response.body.errors.map((e: IDataObject) => e.message);
throw new Error(`Hubspot error response [${error.statusCode}]: ${errorMessages.join(' | ')}`);
}
throw error;
}
}
/**
* Make an API request to paginated hubspot endpoint
* and return all results