mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
e77fd5d286
Ensure all errors in `nodes-base` are `ApplicationError` or children of it and contain no variables in the message, to continue normalizing all the backend errors we report to Sentry. Also, skip reporting to Sentry errors from user input and from external APIs. In future we should refine `ApplicationError` to more specific errors. Follow-up to: [#7877](https://github.com/n8n-io/n8n/pull/7877) - [x] Test workflows: https://github.com/n8n-io/n8n/actions/runs/7084627970 - [x] e2e: https://github.com/n8n-io/n8n/actions/runs/7084936861 --------- Co-authored-by: Michael Kret <michael.k@radency.com>
86 lines
1.9 KiB
TypeScript
86 lines
1.9 KiB
TypeScript
import type {
|
|
IExecuteFunctions,
|
|
ILoadOptionsFunctions,
|
|
IHookFunctions,
|
|
IWebhookFunctions,
|
|
JsonObject,
|
|
} from 'n8n-workflow';
|
|
import { ApplicationError, NodeApiError } from 'n8n-workflow';
|
|
|
|
interface IFormIoCredentials {
|
|
environment: 'cloudHosted' | ' selfHosted';
|
|
domain?: string;
|
|
email: string;
|
|
password: string;
|
|
}
|
|
|
|
/**
|
|
* Method has the logic to get jwt token from Form.io
|
|
*/
|
|
async function getToken(
|
|
this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,
|
|
credentials: IFormIoCredentials,
|
|
) {
|
|
const base = credentials.domain || 'https://formio.form.io';
|
|
const options = {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
method: 'POST',
|
|
body: {
|
|
data: {
|
|
email: credentials.email,
|
|
password: credentials.password,
|
|
},
|
|
},
|
|
uri: `${base}/user/login`,
|
|
json: true,
|
|
resolveWithFullResponse: true,
|
|
};
|
|
|
|
try {
|
|
const responseObject = await this.helpers.request(options);
|
|
return responseObject.headers['x-jwt-token'];
|
|
} catch (error) {
|
|
throw new ApplicationError(
|
|
'Authentication Failed for Form.io. Please provide valid credentails/ endpoint details',
|
|
{ level: 'warning' },
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Method will call register or list webhooks based on the passed method in the parameter
|
|
*/
|
|
export async function formIoApiRequest(
|
|
this: IHookFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
|
method: string,
|
|
endpoint: string,
|
|
body = {},
|
|
qs = {},
|
|
): Promise<any> {
|
|
const credentials = (await this.getCredentials('formIoApi')) as unknown as IFormIoCredentials;
|
|
|
|
const token = await getToken.call(this, credentials);
|
|
|
|
const base = credentials.domain || 'https://api.form.io';
|
|
|
|
const options = {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-jwt-token': token,
|
|
},
|
|
method,
|
|
body,
|
|
qs,
|
|
uri: `${base}${endpoint}`,
|
|
json: true,
|
|
};
|
|
|
|
try {
|
|
return await this.helpers.request.call(this, options);
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
|
}
|
|
}
|