mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
✨ Improve node error handling (#1309)
* Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * 🚧 create basic setup NodeError * 🚧 add httpCodes * 🚧 add path priolist * 🚧 handle statusCode in error, adjust interfaces * 🚧 fixing type issues w/Ivan * 🚧 add error exploration * 👔 fix linter issues * 🔧 improve object check * 🚧 remove path passing from NodeApiError * 🚧 add multi error + refactor findProperty method * 👔 allow any * 🔧 handle multi error message callback * ⚡ change return type of callback * ⚡ add customCallback to MultiError * 🚧 refactor to use INode * 🔨 handle arrays, continue search after first null property found * 🚫 refactor method access * 🚧 setup NodeErrorView * ⚡ change timestamp to Date.now * 📚 Add documentation for methods and constants * 🚧 change message setting * 🚚 move NodeErrors to workflow * ✨ add new ErrorView for Nodes * 🎨 improve error notification * 🎨 refactor interfaces * ⚡ add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * 🎨 rename param * 🐛 fix handling normal errors * ⚡ add usage of NodeApiError * 🎨 fix throw new error instead of constructor * 🎨 remove unnecessary code/comments * 🎨 adjusted spacing + updated status messages * 🎨 fix tab indentation * ✨ Replace current errors with custom errors (#1576) * ⚡ Introduce NodeApiError in catch blocks * ⚡ Introduce NodeOperationError in nodes * ⚡ Add missing errors and remove incompatible * ⚡ Fix NodeOperationError in incompatible nodes * 🔧 Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * 🔨 Adjust Strava Trigger node error handling * 🔨 Adjust AWS nodes error handling * 🔨 Remove duplicate instantiation of NodeApiError * 🐛 fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * 🐛 Remove type annotation from catch variable * ✨ Add XML parsing to NodeApiError * ⚡ Simplify error handling in Rekognition node * ⚡ Pass in XML flag in generic functions * 🔥 Remove try/catch wrappers at call sites * 🔨 Refactor setting description from XML * 🔨 Refactor let to const in resource loaders * ⚡ Find property in parsed XML * ⚡ Change let to const * 🔥 Remove unneeded try/catch block * 👕 Fix linting issues * 🐛 Fix errors from merge conflict resolution * ⚡ Add custom errors to latest contributions * 👕 Fix linting issues * ⚡ Refactor MongoDB helpers for custom errors * 🐛 Correct custom error type * ⚡ Apply feedback to A nodes * ⚡ Apply feedback to missed A node * ⚡ Apply feedback to B-D nodes * ⚡ Apply feedback to E-F nodes * ⚡ Apply feedback to G nodes * ⚡ Apply feedback to H-L nodes * ⚡ Apply feedback to M nodes * ⚡ Apply feedback to P nodes * ⚡ Apply feedback to R nodes * ⚡ Apply feedback to S nodes * ⚡ Apply feedback to T nodes * ⚡ Apply feedback to V-Z nodes * ⚡ Add HTTP code to iterable node error * 🔨 Standardize e as error * 🔨 Standardize err as error * ⚡ Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string,
|
||||
@@ -36,25 +36,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleAnalyticsOAuth2', options);
|
||||
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
let errorMessages;
|
||||
|
||||
if (error.response.body.error.errors) {
|
||||
// Try to return the error prettier
|
||||
errorMessages = error.response.body.error.errors;
|
||||
|
||||
errorMessages = errorMessages.map((errorItem: IDataObject) => errorItem.message);
|
||||
|
||||
errorMessages = errorMessages.join('|');
|
||||
|
||||
} else if (error.response.body.error.message) {
|
||||
errorMessages = error.response.body.error.message;
|
||||
}
|
||||
|
||||
throw new Error(`Google Analytics error response [${error.statusCode}]: ${errorMessages}`);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError, NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as moment from 'moment-timezone';
|
||||
@@ -40,7 +40,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
const credentials = this.getCredentials('googleApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||
}
|
||||
|
||||
const { access_token } = await getAccessToken.call(this, credentials as IDataObject);
|
||||
@@ -53,24 +53,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleBooksOAuth2Api', options);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
let errors;
|
||||
|
||||
if (error.response.body.error.errors) {
|
||||
errors = error.response.body.error.errors;
|
||||
|
||||
errors = errors.map((e: IDataObject) => e.message).join('|');
|
||||
|
||||
} else {
|
||||
errors = error.response.body.error.message;
|
||||
}
|
||||
// Try to return the error prettier
|
||||
throw new Error(
|
||||
`Google Books error response [${error.statusCode}]: ${errors}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
@@ -33,17 +33,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleCalendarOAuth2Api', options);
|
||||
} catch (error) {
|
||||
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 Calendar error response [${error.statusCode}]: ${errors.join('|')}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeApiError,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -208,11 +210,7 @@ export class GoogleCalendar implements INodeType {
|
||||
);
|
||||
|
||||
if (responseData.calendars[calendarId].errors) {
|
||||
let errors = responseData.calendars[calendarId].errors;
|
||||
errors = errors.map((e: IDataObject) => e.reason);
|
||||
throw new Error(
|
||||
`Google Calendar error response: ${errors.join('|')}`,
|
||||
);
|
||||
throw new NodeApiError(this.getNode(), responseData.calendars[calendarId]);
|
||||
}
|
||||
|
||||
if (outputFormat === 'availability') {
|
||||
@@ -328,7 +326,7 @@ export class GoogleCalendar implements INodeType {
|
||||
additionalFields.repeatHowManyTimes &&
|
||||
additionalFields.repeatUntil
|
||||
) {
|
||||
throw new Error(
|
||||
throw new NodeOperationError(this.getNode(),
|
||||
`You can set either 'Repeat How Many Times' or 'Repeat Until' but not both`,
|
||||
);
|
||||
}
|
||||
@@ -573,7 +571,7 @@ export class GoogleCalendar implements INodeType {
|
||||
body.recurrence = [`RRULE:${updateFields.rrule}`];
|
||||
} else {
|
||||
if (updateFields.repeatHowManyTimes && updateFields.repeatUntil) {
|
||||
throw new Error(
|
||||
throw new NodeOperationError(this.getNode(),
|
||||
`You can set either 'Repeat How Many Times' or 'Repeat Until' but not both`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string,
|
||||
@@ -36,24 +36,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleCloudNaturalLanguageOAuth2Api', options);
|
||||
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
let errorMessages;
|
||||
|
||||
if (error.response.body.error.errors) {
|
||||
// Try to return the error prettier
|
||||
errorMessages = error.response.body.error.errors;
|
||||
|
||||
errorMessages = errorMessages.map((errorItem: IDataObject) => errorItem.message);
|
||||
|
||||
errorMessages = errorMessages.join('|');
|
||||
|
||||
} else if (error.response.body.error.message) {
|
||||
errorMessages = error.response.body.error.message;
|
||||
}
|
||||
|
||||
throw new Error(`Google Cloud Natural Language error response [${error.statusCode}]: ${errorMessages}`);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
@@ -34,26 +34,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleContactsOAuth2Api', options);
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
let errors;
|
||||
|
||||
if (error.response.body.error.errors) {
|
||||
|
||||
errors = error.response.body.error.errors;
|
||||
|
||||
errors = errors.map((e: IDataObject) => e.message).join('|');
|
||||
|
||||
} else {
|
||||
errors = error.response.body.error.message;
|
||||
}
|
||||
|
||||
// Try to return the error prettier
|
||||
throw new Error(
|
||||
`Google Contacts error response [${error.statusCode}]: ${errors}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError, NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as moment from 'moment-timezone';
|
||||
@@ -39,7 +39,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
const credentials = this.getCredentials('googleApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||
}
|
||||
|
||||
const { access_token } = await getAccessToken.call(this, credentials as IDataObject);
|
||||
@@ -51,27 +51,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleDriveOAuth2Api', options);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
let errorMessages;
|
||||
|
||||
if (error.response.body.error.errors) {
|
||||
// Try to return the error prettier
|
||||
errorMessages = error.response.body.error.errors;
|
||||
|
||||
errorMessages = errorMessages.map((errorItem: IDataObject) => errorItem.message);
|
||||
|
||||
errorMessages = errorMessages.join('|');
|
||||
|
||||
} else if (error.response.body.error.message) {
|
||||
errorMessages = error.response.body.error.message;
|
||||
} else if (error.response.body.error_description) {
|
||||
errorMessages = error.response.body.error_description;
|
||||
}
|
||||
|
||||
throw new Error(`Google Drive error response [${error.statusCode}]: ${errorMessages}`);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -2146,13 +2147,13 @@ export class GoogleDrive implements INodeType {
|
||||
const item = items[i];
|
||||
|
||||
if (item.binary === undefined) {
|
||||
throw new Error('No binary data exists on item!');
|
||||
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
|
||||
}
|
||||
|
||||
const propertyNameUpload = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||
|
||||
if (item.binary[propertyNameUpload] === undefined) {
|
||||
throw new Error(`No binary data property "${propertyNameUpload}" does not exists on item!`);
|
||||
throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`);
|
||||
}
|
||||
|
||||
if (item.binary[propertyNameUpload].mimeType) {
|
||||
@@ -2294,7 +2295,7 @@ export class GoogleDrive implements INodeType {
|
||||
returnData.push(response as IDataObject);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`The resource "${resource}" is not known!`);
|
||||
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
// INodeTypeDescription,
|
||||
// INodeType,
|
||||
// IWebhookResponseData,
|
||||
// NodeOperationError,
|
||||
// } from 'n8n-workflow';
|
||||
|
||||
// import { getAuthenticationClient } from './GoogleApi';
|
||||
@@ -75,8 +76,8 @@
|
||||
|
||||
// // try {
|
||||
// // await githubApiRequest.call(this, 'GET', endpoint, {});
|
||||
// // } catch (e) {
|
||||
// // if (e.message.includes('[404]:')) {
|
||||
// // } catch (error) {
|
||||
// // if (error.message.includes('[404]:')) {
|
||||
// // // Webhook does not exist
|
||||
// // delete webhookData.webhookId;
|
||||
// // delete webhookData.webhookEvents;
|
||||
@@ -100,7 +101,7 @@
|
||||
// const credentials = this.getCredentials('googleApi');
|
||||
|
||||
// if (credentials === undefined) {
|
||||
// throw new Error('No credentials got returned!');
|
||||
// throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||
// }
|
||||
|
||||
// const scopes = [
|
||||
@@ -165,9 +166,9 @@
|
||||
// // let responseData;
|
||||
// // try {
|
||||
// // responseData = await githubApiRequest.call(this, 'POST', endpoint, body);
|
||||
// // } catch (e) {
|
||||
// // if (e.message.includes('[422]:')) {
|
||||
// // throw new Error('A webhook with the identical URL exists already. Please delete it manually on Github!');
|
||||
// // } catch (error) {
|
||||
// // if (error.message.includes('[422]:')) {
|
||||
// // throw new NodeOperationError(this.getNode(), 'A webhook with the identical URL exists already. Please delete it manually on Github!');
|
||||
// // }
|
||||
|
||||
// // throw e;
|
||||
@@ -175,7 +176,7 @@
|
||||
|
||||
// // if (responseData.id === undefined || responseData.active !== true) {
|
||||
// // // Required data is missing so was not successful
|
||||
// // throw new Error('Github webhook creation response did not contain the expected data.');
|
||||
// // throw new NodeOperationError(this.getNode(), 'Github webhook creation response did not contain the expected data.');
|
||||
// // }
|
||||
|
||||
// // const webhookData = this.getWorkflowStaticData('node');
|
||||
@@ -192,7 +193,7 @@
|
||||
// const credentials = this.getCredentials('googleApi');
|
||||
|
||||
// if (credentials === undefined) {
|
||||
// throw new Error('No credentials got returned!');
|
||||
// throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||
// }
|
||||
|
||||
// const scopes = [
|
||||
@@ -234,7 +235,7 @@
|
||||
|
||||
// // try {
|
||||
// // await githubApiRequest.call(this, 'DELETE', endpoint, body);
|
||||
// // } catch (e) {
|
||||
// // } catch (error) {
|
||||
// // return false;
|
||||
// // }
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri: string | null = null): Promise<any> { // tslint:disable-line:no-any
|
||||
@@ -35,25 +35,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleFirebaseCloudFirestoreOAuth2Api', options);
|
||||
} catch (error) {
|
||||
let errors;
|
||||
|
||||
if (error.response && error.response.body) {
|
||||
|
||||
if (Array.isArray(error.response.body)) {
|
||||
|
||||
errors = error.response.body;
|
||||
|
||||
errors = errors.map((e: { error: { message: string } }) => e.error.message).join('|');
|
||||
} else {
|
||||
errors = error.response.body.error.message;
|
||||
}
|
||||
|
||||
// Try to return the error prettier
|
||||
throw new Error(
|
||||
`Google Firebase error response [${error.statusCode}]: ${errors}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, projectId: string, method: string, resource: string, body: any = {}, qs: IDataObject = {}, headers: IDataObject = {}, uri: string | null = null): Promise<any> { // tslint:disable-line:no-any
|
||||
@@ -34,26 +34,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
|
||||
return await this.helpers.requestOAuth2!.call(this, 'googleFirebaseRealtimeDatabaseOAuth2Api', options);
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
let errors;
|
||||
|
||||
if (error.response.body.error.errors) {
|
||||
|
||||
errors = error.response.body.error.errors;
|
||||
|
||||
errors = errors.map((e: IDataObject) => e.message).join('|');
|
||||
|
||||
} else {
|
||||
errors = error.response.body.error.message;
|
||||
}
|
||||
|
||||
// Try to return the error prettier
|
||||
throw new Error(
|
||||
`Google Firebase error response [${error.statusCode}]: ${errors}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeApiError,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -144,7 +146,7 @@ export class RealtimeDatabase implements INodeType {
|
||||
//https://firebase.google.com/docs/reference/rest/database
|
||||
|
||||
if (['push', 'create', 'update'].includes(operation) && items.length === 1 && Object.keys(items[0].json).length === 0) {
|
||||
throw new Error(`The ${operation} operation needs input data`);
|
||||
throw new NodeOperationError(this.getNode(), `The ${operation} operation needs input data`);
|
||||
}
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
@@ -185,7 +187,7 @@ export class RealtimeDatabase implements INodeType {
|
||||
|
||||
if (responseData === null) {
|
||||
if (operation === 'get') {
|
||||
throw new Error(`Google Firebase error response: Requested entity was not found.`);
|
||||
throw new NodeApiError(this.getNode(), responseData, { message: `Requested entity was not found.` });
|
||||
} else if (method === 'DELETE') {
|
||||
responseData = { success: true };
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -328,7 +329,7 @@ export class GSuiteAdmin implements INodeType {
|
||||
}
|
||||
|
||||
if (qs.projection === 'custom' && qs.customFieldMask === undefined) {
|
||||
throw new Error('When projection is set to custom, the custom schemas field must be defined');
|
||||
throw new NodeOperationError(this.getNode(), 'When projection is set to custom, the custom schemas field must be defined');
|
||||
}
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
@@ -361,7 +362,7 @@ export class GSuiteAdmin implements INodeType {
|
||||
}
|
||||
|
||||
if (qs.projection === 'custom' && qs.customFieldMask === undefined) {
|
||||
throw new Error('When projection is set to custom, the custom schemas field must be defined');
|
||||
throw new NodeOperationError(this.getNode(), 'When projection is set to custom, the custom schemas field must be defined');
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
@@ -33,17 +34,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'gSuiteAdminOAuth2Api', options);
|
||||
} catch (error) {
|
||||
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(
|
||||
`G Suite Admin error response [${error.statusCode}]: ${errors.join('|')}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import {
|
||||
IBinaryKeyData,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
NodeApiError,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -58,7 +60,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
const credentials = this.getCredentials('googleApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||
}
|
||||
|
||||
const { access_token } = await getAccessToken.call(this, credentials as IDataObject);
|
||||
@@ -72,27 +74,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
let errorMessages;
|
||||
|
||||
if (error.response.body.error.errors) {
|
||||
// Try to return the error prettier
|
||||
errorMessages = error.response.body.error.errors;
|
||||
|
||||
errorMessages = errorMessages.map((errorItem: IDataObject) => errorItem.message);
|
||||
|
||||
errorMessages = errorMessages.join('|');
|
||||
|
||||
} else if (error.response.body.error.message) {
|
||||
errorMessages = error.response.body.error.message;
|
||||
} else if (error.response.body.error_description) {
|
||||
errorMessages = error.response.body.error_description;
|
||||
}
|
||||
|
||||
throw new Error(`Gmail error response [${error.statusCode}]: ${errorMessages}`);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError, NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as moment from 'moment-timezone';
|
||||
@@ -40,7 +40,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
const credentials = this.getCredentials('googleApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||
}
|
||||
|
||||
const { access_token } = await getAccessToken.call(this, credentials as IDataObject);
|
||||
@@ -53,11 +53,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleSheetsOAuth2Api', options);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.message) {
|
||||
// Try to return the error prettier
|
||||
throw new Error(`Google Sheet error response [${error.statusCode}]: ${error.response.body.message}`);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -283,7 +283,7 @@ export class GoogleSheet {
|
||||
const rangeEndSplit = rangeEnd.match(/([a-zA-Z]{1,10})([0-9]{0,10})/);
|
||||
|
||||
if (rangeStartSplit === null || rangeStartSplit.length !== 3 || rangeEndSplit === null || rangeEndSplit.length !== 3) {
|
||||
throw new Error(`The range "${range}" is not valid.`);
|
||||
throw new NodeOperationError(this.executeFunctions.getNode(), `The range "${range}" is not valid.`);
|
||||
}
|
||||
|
||||
const keyRowRange = `${sheet ? sheet + '!' : ''}${rangeStartSplit[1]}${dataStartRowIndex}:${rangeEndSplit[1]}${dataStartRowIndex}`;
|
||||
@@ -291,7 +291,7 @@ export class GoogleSheet {
|
||||
const sheetDatakeyRow = await this.getData(this.encodeRange(keyRowRange), valueRenderMode);
|
||||
|
||||
if (sheetDatakeyRow === undefined) {
|
||||
throw new Error('Could not retrieve the key row!');
|
||||
throw new NodeOperationError(this.executeFunctions.getNode(), 'Could not retrieve the key row!');
|
||||
}
|
||||
|
||||
const keyColumnOrder = sheetDatakeyRow[0];
|
||||
@@ -299,7 +299,7 @@ export class GoogleSheet {
|
||||
const keyIndex = keyColumnOrder.indexOf(indexKey);
|
||||
|
||||
if (keyIndex === -1) {
|
||||
throw new Error(`Could not find column for key "${indexKey}"!`);
|
||||
throw new NodeOperationError(this.executeFunctions.getNode(), `Could not find column for key "${indexKey}"!`);
|
||||
}
|
||||
|
||||
const startRowIndex = rangeStartSplit[2] || '';
|
||||
@@ -311,7 +311,7 @@ export class GoogleSheet {
|
||||
const sheetDataKeyColumn = await this.getData(this.encodeRange(keyColumnRange), valueRenderMode);
|
||||
|
||||
if (sheetDataKeyColumn === undefined) {
|
||||
throw new Error('Could not retrieve the key column!');
|
||||
throw new NodeOperationError(this.executeFunctions.getNode(), 'Could not retrieve the key column!');
|
||||
}
|
||||
|
||||
// TODO: The data till here can be cached optionally. Maybe add an option which can
|
||||
@@ -397,7 +397,7 @@ export class GoogleSheet {
|
||||
|
||||
if (keyRowIndex < 0 || dataStartRowIndex < keyRowIndex || keyRowIndex >= inputData.length) {
|
||||
// The key row does not exist so it is not possible to look up the data
|
||||
throw new Error(`The key row does not exist!`);
|
||||
throw new NodeOperationError(this.executeFunctions.getNode(), `The key row does not exist!`);
|
||||
}
|
||||
|
||||
// Create the keys array
|
||||
@@ -417,7 +417,7 @@ export class GoogleSheet {
|
||||
returnColumnIndex = keys.indexOf(lookupValue.lookupColumn);
|
||||
|
||||
if (returnColumnIndex === -1) {
|
||||
throw new Error(`The column "${lookupValue.lookupColumn}" could not be found!`);
|
||||
throw new NodeOperationError(this.executeFunctions.getNode(), `The column "${lookupValue.lookupColumn}" could not be found!`);
|
||||
}
|
||||
|
||||
// Loop over all the items and find the one with the matching value
|
||||
@@ -460,7 +460,7 @@ export class GoogleSheet {
|
||||
const keyColumnData = await this.getData(getRange, 'UNFORMATTED_VALUE');
|
||||
|
||||
if (keyColumnData === undefined) {
|
||||
throw new Error('Could not retrieve the column data!');
|
||||
throw new NodeOperationError(this.executeFunctions.getNode(), 'Could not retrieve the column data!');
|
||||
}
|
||||
|
||||
const keyColumnOrder = keyColumnData[0];
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -987,7 +988,7 @@ export class GoogleSheets implements INodeType {
|
||||
const responseData = await sheet.spreadsheetGetSheets();
|
||||
|
||||
if (responseData === undefined) {
|
||||
throw new Error('No data got returned');
|
||||
throw new NodeOperationError(this.getNode(), 'No data got returned');
|
||||
}
|
||||
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as moment from 'moment-timezone';
|
||||
@@ -53,11 +54,7 @@ export async function googleApiRequest(
|
||||
return await this.helpers.requestOAuth2!.call(this, 'googleSlidesOAuth2Api', options);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
if (error?.response?.body?.message) {
|
||||
throw new Error(`Google Slides error response [${error.statusCode}]: ${error.response.body.message}`);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(
|
||||
@@ -46,17 +46,7 @@ export async function googleApiRequest(
|
||||
options,
|
||||
);
|
||||
} catch (error) {
|
||||
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}]: ${errors.join('|')}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError, NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as moment from 'moment-timezone';
|
||||
@@ -40,7 +40,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
const credentials = this.getCredentials('googleApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||
}
|
||||
|
||||
const { access_token } = await getAccessToken.call(this, credentials as IDataObject);
|
||||
@@ -53,11 +53,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
return await this.helpers.requestOAuth2.call(this, 'googleTranslateOAuth2Api', options);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.message) {
|
||||
// Try to return the error prettier
|
||||
throw new Error(`Google Translate error response [${error.statusCode}]: ${error.response.body.message}`);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
@@ -33,28 +33,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'youTubeOAuth2Api', options);
|
||||
} catch (error) {
|
||||
|
||||
let errors;
|
||||
|
||||
if (error.response && error.response.body) {
|
||||
|
||||
if (resource === '/upload/youtube/v3/videos') {
|
||||
error.response.body = JSON.parse(error.response.body);
|
||||
}
|
||||
|
||||
if (error.response.body.error) {
|
||||
|
||||
errors = error.response.body.error.errors;
|
||||
|
||||
errors = errors.map((e: IDataObject) => e.message);
|
||||
}
|
||||
|
||||
// Try to return the error prettier
|
||||
throw new Error(
|
||||
`YouTube error response [${error.statusCode}]: ${errors.join('|')}`,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
@@ -414,11 +415,11 @@ export class YouTube implements INodeType {
|
||||
const item = items[i];
|
||||
|
||||
if (item.binary === undefined) {
|
||||
throw new Error('No binary data exists on item!');
|
||||
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
|
||||
}
|
||||
|
||||
if (item.binary[binaryProperty] === undefined) {
|
||||
throw new Error(`No binary data property "${binaryProperty}" does not exists on item!`);
|
||||
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryProperty}" does not exists on item!`);
|
||||
}
|
||||
|
||||
if (item.binary[binaryProperty].mimeType) {
|
||||
@@ -827,7 +828,7 @@ export class YouTube implements INodeType {
|
||||
}
|
||||
|
||||
if (qs.relatedToVideoId && qs.forDeveloper !== undefined) {
|
||||
throw new Error(`When using the parameter 'related to video' the parameter 'for developer' cannot be set`);
|
||||
throw new NodeOperationError(this.getNode(), `When using the parameter 'related to video' the parameter 'for developer' cannot be set`);
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
@@ -901,11 +902,11 @@ export class YouTube implements INodeType {
|
||||
const item = items[i];
|
||||
|
||||
if (item.binary === undefined) {
|
||||
throw new Error('No binary data exists on item!');
|
||||
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
|
||||
}
|
||||
|
||||
if (item.binary[binaryProperty] === undefined) {
|
||||
throw new Error(`No binary data property "${binaryProperty}" does not exists on item!`);
|
||||
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryProperty}" does not exists on item!`);
|
||||
}
|
||||
|
||||
if (item.binary[binaryProperty].mimeType) {
|
||||
|
||||
Reference in New Issue
Block a user