refactor(core): fix for no-uncaught-json-parse warnings

This commit is contained in:
Michael Kret
2022-10-21 21:52:43 +03:00
committed by GitHub
parent ca9eca9ae9
commit 1d57b10942
36 changed files with 150 additions and 93 deletions

View File

@@ -7,7 +7,7 @@ import {
IWebhookFunctions,
} from 'n8n-core';
import { IDataObject, IHttpRequestOptions, NodeApiError } from 'n8n-workflow';
import { IDataObject, IHttpRequestOptions, jsonParse, NodeApiError } from 'n8n-workflow';
export async function awsApiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
@@ -18,7 +18,7 @@ export async function awsApiRequest(
query: IDataObject = {},
headers?: object,
// tslint:disable-next-line:no-any
): Promise<any> {
): Promise<any> {
const credentials = await this.getCredentials('aws');
const requestOptions = {
@@ -50,7 +50,7 @@ export async function awsApiRequestREST(
query: IDataObject = {},
headers?: object,
// tslint:disable-next-line:no-any
): Promise<any> {
): Promise<any> {
const response = await awsApiRequest.call(this, service, method, path, body, query, headers);
try {
return JSON.parse(response);
@@ -70,23 +70,17 @@ export async function awsApiRequestAllItems(
headers: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
do {
responseData = await awsApiRequestREST.call(
this,
service,
method,
path,
body,
query,
headers,
);
responseData = await awsApiRequestREST.call(this, service, method, path, body, query, headers);
if (responseData.NextToken) {
const data = JSON.parse(body as string);
// tslint:disable-next-line:no-any
const data = jsonParse<any>(body as string, {
errorMessage: 'Response body is not valid JSON',
});
data['NextToken'] = responseData.NextToken;
}
returnData.push.apply(returnData, get(responseData, propertyName));