Improvements to Google Tasks node

This commit is contained in:
ricardo
2020-06-17 17:15:54 -04:00
parent 8116b5f970
commit d261eb5a12
4 changed files with 77 additions and 87 deletions

View File

@@ -1,12 +1,16 @@
import { OptionsWithUri } from 'request';
import {
OptionsWithUri,
} from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions
ILoadOptionsFunctions,
} from 'n8n-core';
import { IDataObject } from 'n8n-workflow';
import {
IDataObject,
} from 'n8n-workflow';
export async function googleApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
@@ -27,6 +31,7 @@ export async function googleApiRequest(
uri: uri || `https://www.googleapis.com${resource}`,
json: true
};
try {
if (Object.keys(headers).length !== 0) {
options.headers = Object.assign({}, options.headers, headers);
@@ -41,10 +46,14 @@ export async function googleApiRequest(
options
);
} catch (error) {
if (error.response && error.response.body && error.response.body.message) {
if (error.response && error.response.body && error.response.body.error) {
let errors = error.response.body.error.errors;
errors = errors.map((e: IDataObject) => e.message);
// Try to return the error prettier
throw new Error(
`Google Tasks error response [${error.statusCode}]: ${error.response.body.message}`
`Google Tasks error response [${error.statusCode}]: ${errors.join('|')}`
);
}
throw error;