Skip to content

Commit

Permalink
added shim to allow test to pass while server is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jul 29, 2021
1 parent fdda23b commit 5921009
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions nats-base-client/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class Bucket implements KV {
await this.js.publish(this.subjectForKey(k), Empty, { headers: h });
}

consumerOn(k: string, lastOnly = false): Promise<ConsumerInfo> {
async consumerOn(k: string, lastOnly = false): Promise<ConsumerInfo> {
const ji = this.js as JetStreamClientImpl;
const nc = ji.nc;
const inbox = createInbox(nc.options.inboxPrefix);
Expand All @@ -264,8 +264,24 @@ export class Bucket implements KV {
"filter_subject": this.subjectForKey(k),
"flow_control": k === "*",
};

return this.jsm.consumers.add(this.stream, opts);
try {
const ci = await this.jsm.consumers.add(this.stream, opts);
return ci;
} catch (err) {
if (
err.message === "invalid json" &&
opts.deliver_policy === DeliverPolicy.LastPerSubject
) {
// FIXME: this here while supported server becomes available
console.error(
`\u001B[33m KV feature running on a non-supported server \u001B[0m`,
);
opts.deliver_policy = DeliverPolicy.Last;
return await this.jsm.consumers.add(this.stream, opts);
} else {
throw err;
}
}
}

async history(k: string): Promise<QueuedIterator<Entry>> {
Expand Down

0 comments on commit 5921009

Please sign in to comment.