From 6d9783c5f55cd14ea51149200ac0539e3574f7ba Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Thu, 25 May 2023 11:46:00 -0400 Subject: [PATCH] fix(tautulli): More response formatting safeguards #77 * Log warning if payload is empty * Destructure request body with default empty object --- src/sources/TautulliSource.ts | 40 ++++++++++--------- .../ingressNotifiers/TautulliNotifier.ts | 5 ++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/sources/TautulliSource.ts b/src/sources/TautulliSource.ts index 2550368b..588c9666 100644 --- a/src/sources/TautulliSource.ts +++ b/src/sources/TautulliSource.ts @@ -17,25 +17,27 @@ export default class TautulliSource extends PlexSource { static formatPlayObj(obj: Request, options: FormatPlayObjectOptions = {}): PlayObject { const {newFromSource = false} = options; const { - artist_name, - track_name, - track_artist, - album_name, - media_type, - title, - library_name, - server, - version, - duration, - username, - library, - machine_id = '', - session_key, - action, - platform, - device, - player, - } = obj.body; + body :{ + artist_name, + track_name, + track_artist, + album_name, + media_type, + title, + library_name, + server, + version, + duration, + username, + library, + machine_id = '', + session_key, + action, + platform, + device, + player, + } = {} + } = obj; let artists = [artist_name]; if (track_artist !== undefined && track_artist !== artist_name) { artists.push(track_artist); diff --git a/src/sources/ingressNotifiers/TautulliNotifier.ts b/src/sources/ingressNotifiers/TautulliNotifier.ts index 81743ae0..7e070ef2 100644 --- a/src/sources/ingressNotifiers/TautulliNotifier.ts +++ b/src/sources/ingressNotifiers/TautulliNotifier.ts @@ -16,7 +16,10 @@ export class TautulliNotifier extends IngressNotifier { if(!this.seenServers.includes(playObj.meta.server)) { this.seenServers.push(playObj.meta.server); - let msg = [`Received valid data from server ${playObj.meta.server} for the first time.`]; + let msg = [`Received data from server ${playObj.meta.server} for the first time.`]; + if(req.body === undefined) { + msg.push('WARNING: Payload was empty.'); + } if(playObj.meta.library === undefined) { msg.push('WARNING: library was not defined in payload. If you want to filter plays by library this must be present in webhook payload.'); }