feat(editor): Improve errors in output panel (#8644)

Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
Giulio Andreini
2024-03-07 17:08:01 +01:00
committed by GitHub
parent 6e2aa405fc
commit 5301323906
38 changed files with 772 additions and 287 deletions

View File

@@ -57,31 +57,13 @@ export async function googleApiRequest(
);
}
} catch (error) {
if (error instanceof NodeApiError) throw error;
if (error.code === 'ERR_OSSL_PEM_NO_START_LINE') {
error.statusCode = '401';
}
const apiError = new NodeApiError(
this.getNode(),
{
reason: error.error,
} as JsonObject,
{ httpCode: String(error.statusCode) },
);
if (
apiError.message &&
apiError.description &&
(apiError.message.toLowerCase().includes('bad request') ||
apiError.message.toLowerCase().includes('forbidden') ||
apiError.message.toUpperCase().includes('UNKNOWN ERROR'))
) {
const message = apiError.message;
apiError.message = apiError.description;
apiError.description = message;
}
throw apiError;
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}

View File

@@ -1,4 +1,4 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { type IExecuteFunctions, type IDataObject, type INodeExecutionData } from 'n8n-workflow';
import { GoogleSheet } from '../helpers/GoogleSheet';
import { getSpreadsheetId } from '../helpers/GoogleSheets.utils';
import type { GoogleSheets, ResourceLocator } from '../helpers/GoogleSheets.types';
@@ -72,20 +72,11 @@ export async function router(this: IExecuteFunctions): Promise<INodeExecutionDat
if (results?.length) {
operationResult = operationResult.concat(results);
}
} catch (err) {
} catch (error) {
if (this.continueOnFail()) {
operationResult.push({ json: this.getInputData(0)[0].json, error: err });
operationResult.push({ json: this.getInputData(0)[0].json, error });
} else {
if (
err.message &&
(err.message.toLowerCase().includes('bad request') ||
err.message.toLowerCase().includes('uknown error')) &&
err.description
) {
err.message = err.description;
err.description = undefined;
}
throw err;
throw error;
}
}

View File

@@ -5,7 +5,7 @@ import { wrapData } from '../../../../../../utils/utilities';
export async function execute(
this: IExecuteFunctions,
sheet: GoogleSheet,
_sheet: GoogleSheet,
sheetName: string,
): Promise<INodeExecutionData[]> {
const returnData: INodeExecutionData[] = [];

View File

@@ -139,11 +139,8 @@ export class GoogleSheet {
});
if (!foundItem?.properties?.title) {
throw new NodeOperationError(
node,
`Sheet with ${mode === 'name' ? 'name' : 'ID'} ${value} not found`,
{ level: 'warning' },
);
const error = new Error(`Sheet with ${mode === 'name' ? 'name' : 'ID'} ${value} not found`);
throw new NodeOperationError(node, error, { level: 'warning' });
}
return foundItem.properties;

View File

@@ -9,6 +9,7 @@ import type {
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { getGoogleAccessToken } from '../../../GenericFunctions';
import set from 'lodash/set';
export async function apiRequest(
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
@@ -62,11 +63,15 @@ export async function apiRequest(
error.statusCode = '401';
}
if (error.message.includes('PERMISSION_DENIED')) {
const message = `Missing permissions for Google Sheet, ${error.message}}`;
const details = error.description ? ` Details of the error: ${error.description}.` : '';
const description = `Please check that the account you're using has the right permissions. (If you're trying to modify the sheet, you'll need edit access.)${details}`;
throw new NodeApiError(this.getNode(), error as JsonObject, { message, description });
if (error instanceof NodeApiError) {
if (error.message.includes('PERMISSION_DENIED')) {
const details = error.description ? ` Details of the error: ${error.description}.` : '';
const description = `Please check that the account you're using has the right permissions. (If you're trying to modify the sheet, you'll need edit access.)${details}`;
set(error, 'description', description);
}
throw error;
}
throw new NodeApiError(this.getNode(), error as JsonObject);