Skip to content

Commit

Permalink
Merge pull request #4226 from rmosolgo/ably-dont-pass-empty-data
Browse files Browse the repository at this point in the history
Don't pass along empty initial responses in Ably subscriptions
  • Loading branch information
rmosolgo authored Oct 13, 2022
2 parents b5d5641 + 44db672 commit 3fa4e93
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,41 @@ describe("createAblyHandler", () => {
expect(nextInvokedWith).toBeUndefined()
})

it("doesn't dispatch anything for an empty data object", async () => {
let errorInvokedWith = undefined
let nextInvokedWith = undefined

const producer = createAblyHandler({
fetchOperation: () =>
new Promise(resolve =>
resolve({
headers: new Map([["X-Subscription-ID", "foo"]]),
body: { data: {} }
})
),
ably: createDummyConsumer()
})

producer(
dummyOperation,
{},
{},
{
onError: (errors: any) => {
errorInvokedWith = errors
},
onNext: (response: any) => {
nextInvokedWith = response
},
onCompleted: () => {}
}
)

await nextTick()
expect(errorInvokedWith).toBeUndefined()
expect(nextInvokedWith).toBeUndefined()
})

it("dispatches caught errors", async () => {
let errorInvokedWith = undefined
let nextInvokedWith = undefined
Expand Down
2 changes: 1 addition & 1 deletion javascript_client/src/subscriptions/createAblyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function createAblyHandler(options: AblyHandlerOptions) {
if (result.errors) {
// What kind of error stuff belongs here?
observer.onError(result.errors)
} else if (result.data) {
} else if (result.data && Object.keys(result.data).length > 0) {
observer.onNext({ data: result.data })
}
}
Expand Down

0 comments on commit 3fa4e93

Please sign in to comment.