fix(Strava Trigger Node): Fix issue with webhook not being deleted (#11226)

This commit is contained in:
Jon 2024-10-14 11:17:19 +01:00 committed by GitHub
parent 4f27b39b45
commit 566529ca11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View file

@ -36,14 +36,13 @@ export async function stravaApiRequest(
if (this.getNode().type.includes('Trigger') && resource.includes('/push_subscriptions')) { if (this.getNode().type.includes('Trigger') && resource.includes('/push_subscriptions')) {
const credentials = await this.getCredentials('stravaOAuth2Api'); const credentials = await this.getCredentials('stravaOAuth2Api');
if (method === 'GET') { if (method === 'GET' || method === 'DELETE') {
qs.client_id = credentials.clientId; qs.client_id = credentials.clientId;
qs.client_secret = credentials.clientSecret; qs.client_secret = credentials.clientSecret;
} else { } else {
body.client_id = credentials.clientId; body.client_id = credentials.clientId;
body.client_secret = credentials.clientSecret; body.client_secret = credentials.clientSecret;
} }
return await this.helpers?.request(options); return await this.helpers?.request(options);
} else { } else {
return await this.helpers.requestOAuth2.call(this, 'stravaOAuth2Api', options, { return await this.helpers.requestOAuth2.call(this, 'stravaOAuth2Api', options, {

View file

@ -112,7 +112,7 @@ export class StravaTrigger implements INodeType {
default: false, default: false,
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether // eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
description: 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 { try {
responseData = await stravaApiRequest.call(this, 'POST', endpoint, body); responseData = await stravaApiRequest.call(this, 'POST', endpoint, body);
} catch (error) { } catch (error) {
const apiErrorResponse = error.cause.response; if (error?.cause?.error) {
if (apiErrorResponse?.body?.errors) { const errors = error?.cause?.error?.errors;
const errors = apiErrorResponse.body.errors;
for (error of errors) { for (error of errors) {
// if there is a subscription already created // if there is a subscription already created
if (error.resource === 'PushSubscription' && error.code === 'already exists') { if (error.resource === 'PushSubscription' && error.code === 'already exists') {
@ -177,6 +176,7 @@ export class StravaTrigger implements INodeType {
'DELETE', 'DELETE',
`/push_subscriptions/${webhooks[0].id}`, `/push_subscriptions/${webhooks[0].id}`,
); );
// now there is room create a subscription with the n8n data // now there is room create a subscription with the n8n data
const requestBody = { const requestBody = {
callback_url: webhookUrl, callback_url: webhookUrl,
@ -190,7 +190,7 @@ export class StravaTrigger implements INodeType {
requestBody, requestBody,
); );
} else { } 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; throw error;
} }
} }