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

View file

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

View file

@ -109,12 +109,12 @@ export class Strava implements INodeType {
responseData = await stravaApiRequest.call(this, 'GET', `/activities/${activityId}`); 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 = { const path: IDataObject = {
'getComments': 'comments', 'getComments': 'comments',
'getZones': 'zones', 'getZones': 'zones',
'getKudoers': 'kudoers', 'getKudos': 'kudos',
'getLaps': 'laps', 'getLaps': 'laps',
}; };

View file

@ -161,6 +161,7 @@ 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) {
if (error.response && error.response.body && error.response.body.errors) {
const errors = error.response.body.errors; const errors = error.response.body.errors;
for (error of errors) { for (error of errors) {
// if there is a subscription already created // 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) { if (responseData.id === undefined) {
// Required data is missing so was not successful // Required data is missing so was not successful
return false; return false;