Skip to content

Commit

Permalink
Handle Playlist Error
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbs96 committed Dec 7, 2021
1 parent d734ffb commit 5b22687
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/twinkly.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ class Twinkly {

/**
* Get playlist
* @return {Promise<{playlist: {unique_id: String, entries: {id: Number, handle: Number, name: String, unique_id: String, duration: Number}[]}, code: Number}>}
* @return {Promise<{playlist: {unique_id: String, name: String, entries: {id: Number, handle: Number, name: String, unique_id: String, duration: Number}[]}, code: Number}>}
* @see <a href="https://xled-docs.readthedocs.io/en/latest/rest_api.html#get-playlist">REST-API</a>
*/
async getPlaylist() {
Expand All @@ -1140,10 +1140,10 @@ class Twinkly {
const response = await this._get('playlist');

/**
* @type {{unique_id: String, entries:{id: Number, handle: Number, name: String, unique_id: String, duration: Number}[]}}
* @type {{unique_id: String, name: String, entries:{id: Number, handle: Number, name: String, unique_id: String, duration: Number}[]}}
*/
const playlist = {};
this.getObjectByArray('playlist', playlist, response, ['unique_id', 'entries']);
this.getObjectByArray('playlist', playlist, response, ['unique_id', 'name', 'entries']);

// Liste füllen
for (const entry of playlist.entries) {
Expand All @@ -1152,11 +1152,6 @@ class Twinkly {

return {playlist: playlist, code: response['code']};
} catch (e) {
// Wenn keine Playlist existiert, kommt hier eine Exception
// HTTP Error (204) No Content: {"code":1102}
if (e.message && (e.message.includes('ECONNRESET') || e.message.includes('(204)')))
return {playlist: {unique_id: '', entries: []}, code: HTTPCodes.values.ok};

throw Error(e.message);
}
}
Expand Down Expand Up @@ -1207,6 +1202,11 @@ class Twinkly {

return {playlist : playlist , code: response['code']};
} catch (e) {
// Wenn keine Playlist existiert, kommt hier eine Exception
// HTTP Error (204) No Content: {"code":1102}
if (e.message && (e.message.includes('ECONNRESET') || e.message.includes('(204)')))
return {playlist: {id: -1, unique_id: '', name: '', duration: 0}, code: HTTPCodes.values.ok};

throw Error(e.message);
}
}
Expand Down

0 comments on commit 5b22687

Please sign in to comment.