mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Linear Node): Fix issue with error handling (#12191)
This commit is contained in:
@@ -6,8 +6,7 @@ import type {
|
||||
ILoadOptionsFunctions,
|
||||
IHookFunctions,
|
||||
IWebhookFunctions,
|
||||
JsonObject,
|
||||
IRequestOptions,
|
||||
IHttpRequestOptions,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
@@ -24,24 +23,43 @@ export async function linearApiRequest(
|
||||
const endpoint = 'https://api.linear.app/graphql';
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0, 'apiToken') as string;
|
||||
|
||||
let options: IRequestOptions = {
|
||||
let options: IHttpRequestOptions = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body,
|
||||
uri: endpoint,
|
||||
url: endpoint,
|
||||
json: true,
|
||||
};
|
||||
options = Object.assign({}, options, option);
|
||||
try {
|
||||
return await this.helpers.requestWithAuthentication.call(
|
||||
const response = await this.helpers.httpRequestWithAuthentication.call(
|
||||
this,
|
||||
authenticationMethod === 'apiToken' ? 'linearApi' : 'linearOAuth2Api',
|
||||
options,
|
||||
);
|
||||
|
||||
if (response.errors) {
|
||||
throw new NodeApiError(this.getNode(), response.errors, {
|
||||
message: response.errors[0].message,
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
throw new NodeApiError(
|
||||
this.getNode(),
|
||||
{},
|
||||
{
|
||||
message: error.errorResponse
|
||||
? error.errorResponse[0].message
|
||||
: error.context.data.errors[0].message,
|
||||
description: error.errorResponse
|
||||
? error.errorResponse[0].extensions.userPresentableMessage
|
||||
: error.context.data.errors[0].extensions.userPresentableMessage,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +103,7 @@ export async function validateCredentials(
|
||||
): Promise<any> {
|
||||
const credentials = decryptedCredentials;
|
||||
|
||||
const options: IRequestOptions = {
|
||||
const options: IHttpRequestOptions = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: credentials.apiKey,
|
||||
@@ -97,7 +115,7 @@ export async function validateCredentials(
|
||||
first: 1,
|
||||
},
|
||||
},
|
||||
uri: 'https://api.linear.app/graphql',
|
||||
url: 'https://api.linear.app/graphql',
|
||||
json: true,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user