Fix issues on Strava-Node

This commit is contained in:
Jan Oberhauser 2020-10-22 10:19:17 +02:00
parent 95b33662c9
commit 3e56d5fc08
4 changed files with 79 additions and 61 deletions

View file

@ -1,7 +1,7 @@
import {
INodeProperties,
} from "n8n-workflow";
} from 'n8n-workflow';
export const activityOperations = [
{
@ -37,9 +37,9 @@ export const activityOperations = [
description: 'Get all activity comments',
},
{
name: 'Get Kudoers',
value: 'getKudoers',
description: 'Get all activity kudoers',
name: 'Get Kudos',
value: 'getKudos',
description: 'Get all activity kudos',
},
{
name: 'Get Laps',
@ -78,7 +78,7 @@ export const activityFields = [
'activity',
],
operation: [
'create'
'create',
]
},
},
@ -96,7 +96,7 @@ export const activityFields = [
'activity',
],
operation: [
'create'
'create',
]
},
},
@ -131,7 +131,7 @@ export const activityFields = [
'activity',
],
operation: [
'create'
'create',
]
},
},
@ -191,6 +191,7 @@ export const activityFields = [
},
],
},
/* -------------------------------------------------------------------------- */
/* activity:update */
/* -------------------------------------------------------------------------- */
@ -273,6 +274,7 @@ export const activityFields = [
},
],
},
/* -------------------------------------------------------------------------- */
/* activity:get */
/* -------------------------------------------------------------------------- */
@ -294,6 +296,7 @@ export const activityFields = [
default: '',
description: 'ID or email of activity',
},
/* -------------------------------------------------------------------------- */
/* activity */
/* -------------------------------------------------------------------------- */
@ -308,10 +311,10 @@ export const activityFields = [
'activity',
],
operation: [
'comment',
'lap',
'kudo',
'zone',
'getComments',
'getLaps',
'getKudos',
'getZones',
],
},
},
@ -330,7 +333,7 @@ export const activityFields = [
operation: [
'getComments',
'getLaps',
'getKudoers',
'getKudos',
'getZones',
],
},
@ -350,7 +353,7 @@ export const activityFields = [
operation: [
'getComments',
'getLaps',
'getKudoers',
'getKudos',
'getZones',
],
returnAll: [
@ -365,6 +368,7 @@ export const activityFields = [
default: 50,
description: 'How many results to return.',
},
/* -------------------------------------------------------------------------- */
/* activity:getAll */
/* -------------------------------------------------------------------------- */

View file

@ -89,4 +89,3 @@ export async function stravaApiRequestAllItems(this: IHookFunctions | ILoadOptio
return returnData;
}

View file

@ -109,12 +109,12 @@ export class Strava implements INodeType {
responseData = await stravaApiRequest.call(this, 'GET', `/activities/${activityId}`);
}
if (['getLaps', 'getZones', 'getKudoers', 'getComments'].includes(operation)) {
if (['getLaps', 'getZones', 'getKudos', 'getComments'].includes(operation)) {
const path: IDataObject = {
'getComments': 'comments',
'getZones': 'zones',
'getKudoers': 'kudoers',
'getKudos': 'kudos',
'getLaps': 'laps',
};

View file

@ -161,6 +161,7 @@ export class StravaTrigger implements INodeType {
try {
responseData = await stravaApiRequest.call(this, 'POST', endpoint, body);
} catch (error) {
if (error.response && error.response.body && error.response.body.errors) {
const errors = error.response.body.errors;
for (error of errors) {
// if there is a subscription already created
@ -187,6 +188,20 @@ export class StravaTrigger implements INodeType {
}
}
if (!responseData) {
let errorMessage = '';
if (error.response && error.response.body && error.response.body.message) {
errorMessage = error.response.body.message;
} else {
errorMessage = error.message;
}
throw new Error(
`Strava error response [${error.statusCode}]: ${errorMessage}`
);
}
}
if (responseData.id === undefined) {
// Required data is missing so was not successful
return false;