mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
fix(Strava Trigger Node): Fix issue with webhook not being deleted (#11226)
This commit is contained in:
parent
4f27b39b45
commit
566529ca11
|
@ -36,14 +36,13 @@ export async function stravaApiRequest(
|
|||
|
||||
if (this.getNode().type.includes('Trigger') && resource.includes('/push_subscriptions')) {
|
||||
const credentials = await this.getCredentials('stravaOAuth2Api');
|
||||
if (method === 'GET') {
|
||||
if (method === 'GET' || method === 'DELETE') {
|
||||
qs.client_id = credentials.clientId;
|
||||
qs.client_secret = credentials.clientSecret;
|
||||
} else {
|
||||
body.client_id = credentials.clientId;
|
||||
body.client_secret = credentials.clientSecret;
|
||||
}
|
||||
|
||||
return await this.helpers?.request(options);
|
||||
} else {
|
||||
return await this.helpers.requestOAuth2.call(this, 'stravaOAuth2Api', options, {
|
||||
|
|
|
@ -112,7 +112,7 @@ export class StravaTrigger implements INodeType {
|
|||
default: false,
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
||||
description:
|
||||
'Strava allows just one subscription at all times. If you want to delete the current subscription to make room for a new subcription with the current parameters, set this parameter to true. Keep in mind this is a destructive operation.',
|
||||
'Strava allows just one subscription at all times. If you want to delete the current subscription to make room for a new subscription with the current parameters, set this parameter to true. Keep in mind this is a destructive operation.',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -155,9 +155,8 @@ export class StravaTrigger implements INodeType {
|
|||
try {
|
||||
responseData = await stravaApiRequest.call(this, 'POST', endpoint, body);
|
||||
} catch (error) {
|
||||
const apiErrorResponse = error.cause.response;
|
||||
if (apiErrorResponse?.body?.errors) {
|
||||
const errors = apiErrorResponse.body.errors;
|
||||
if (error?.cause?.error) {
|
||||
const errors = error?.cause?.error?.errors;
|
||||
for (error of errors) {
|
||||
// if there is a subscription already created
|
||||
if (error.resource === 'PushSubscription' && error.code === 'already exists') {
|
||||
|
@ -177,6 +176,7 @@ export class StravaTrigger implements INodeType {
|
|||
'DELETE',
|
||||
`/push_subscriptions/${webhooks[0].id}`,
|
||||
);
|
||||
|
||||
// now there is room create a subscription with the n8n data
|
||||
const requestBody = {
|
||||
callback_url: webhookUrl,
|
||||
|
@ -190,7 +190,7 @@ export class StravaTrigger implements INodeType {
|
|||
requestBody,
|
||||
);
|
||||
} else {
|
||||
error.message = `A subscription already exists [${webhooks[0].callback_url}]. If you want to delete this subcription and create a new one with the current parameters please go to options and set delete if exist to true`;
|
||||
error.message = `A subscription already exists [${webhooks[0].callback_url}]. If you want to delete this subscription and create a new one with the current parameters please go to options and set delete if exist to true`;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue