Skip to content

Commit

Permalink
Allow any payloads for NOTIFY, not just json
Browse files Browse the repository at this point in the history
resolves #2
  • Loading branch information
kabirbaidhya committed Jul 11, 2016
1 parent cf0c03b commit af66045
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ class Listener {
// this.listenTo(client, channels);
}

/**
* Parses the payload and returns it.
* If it's a valid json, parse it and return the decoded object.
* Otherwise, just return the payload string as it is.
*
* @returns {object|string}
*/
parsePayload(str) {
try {
return JSON.parse(str);
} catch (e) {
throw new Error(
'Error parsing the JSON payload. NOTIFY payload should be a valid JSON.' + dim(str)
);
return str;
}
}

Expand Down

0 comments on commit af66045

Please sign in to comment.