mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
🐛 Fix Mautic-Node error reporting
This commit is contained in:
@@ -10,6 +10,25 @@ import {
|
||||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
import { errors } from 'imap-simple';
|
||||
|
||||
interface OMauticErrorResponse {
|
||||
errors: Array<{
|
||||
conde: number;
|
||||
message: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
function getErrors(error: OMauticErrorResponse): string {
|
||||
const returnErrors: string[] = [];
|
||||
|
||||
for (const errorItem of error.errors) {
|
||||
returnErrors.push(errorItem.message);
|
||||
}
|
||||
|
||||
return returnErrors.join(', ');
|
||||
}
|
||||
|
||||
|
||||
export async function mauticApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('mauticApi');
|
||||
@@ -26,14 +45,19 @@ export async function mauticApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||
json: true
|
||||
};
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (err) {
|
||||
const errorMessage = err.error || err.error.message;
|
||||
const returnData = await this.helpers.request!(options);
|
||||
|
||||
if (errorMessage !== undefined) {
|
||||
throw new Error(errorMessage);
|
||||
if (returnData.error) {
|
||||
// They seem to to sometimes return 200 status but still error.
|
||||
throw new Error(getErrors(returnData));
|
||||
}
|
||||
throw err;
|
||||
|
||||
return returnData;
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.errors) {
|
||||
throw new Error('Mautic Error: ' + getErrors(error.response.body));
|
||||
}
|
||||
throw new Error(`Mautic Error: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user