Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: pubsub do not eat error messages (#632)
Browse files Browse the repository at this point in the history
* fix: allow topicCIDs from older peers

* fix: do not eat pubsub message error

* fix: lint errors
  • Loading branch information
richardschneider authored and daviddias committed Nov 22, 2017
1 parent 21596c7 commit 5a1bf9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module.exports = (arg) => {

function subscribe (topic, options, handler, callback) {
ps.on(topic, handler)

if (subscriptions[topic]) {
// TODO: should a callback error be returned?
return callback()
Expand Down
17 changes: 9 additions & 8 deletions src/utils/pubsub-message-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ class PubsubMessageStream extends TransformStream {
}

_transform (obj, enc, callback) {
let msg
try {
msg = PubsubMessage.deserialize(obj, 'base64')
} catch (err) {
// Not a valid pubsub message
// go-ipfs returns '{}' as the very first object atm, we skip that
// go-ipfs returns '{}' as the very first object atm, we skip that
if (Object.keys(obj).length === 0) {
return callback()
}

this.push(msg)
callback()
try {
const msg = PubsubMessage.deserialize(obj, 'base64')
this.push(msg)
callback()
} catch (err) {
return callback(err)
}
}
}

Expand Down

0 comments on commit 5a1bf9b

Please sign in to comment.