Skip to content

Commit

Permalink
[FIX] fixed throw in request - in some environments, correctly so, th…
Browse files Browse the repository at this point in the history
…e promise for the request is not rejected. (#216)
  • Loading branch information
aricart authored Nov 2, 2021
1 parent 2975fd4 commit ce4f4aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion nats-base-client/nats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ export class NatsConnectionImpl implements NatsConnection {
data: Uint8Array = Empty,
opts: RequestOptions = { timeout: 1000, noMux: false },
): Promise<Msg> {
this._check(subject, true, true);
try {
this._check(subject, true, true);
} catch (err) {
return Promise.reject(err);
}
opts.timeout = opts.timeout || 1000;
if (opts.timeout < 1) {
return Promise.reject(new NatsError("timeout", ErrorCode.InvalidOption));
Expand Down
2 changes: 1 addition & 1 deletion src/deno_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from "../nats-base-client/internal_mod.ts";
import type { TlsOptions } from "../nats-base-client/types.ts";

const VERSION = "1.3.0";
const VERSION = "1.3.1";
const LANG = "nats.deno";

// if trying to simply write to the connection for some reason
Expand Down
13 changes: 13 additions & 0 deletions tests/basics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,19 @@ Deno.test("basics - request with custom subject", async () => {
await cleanup(ns, nc);
});

Deno.test("basics - request requires a subject", async () => {
const { ns, nc } = await setup();
await assertThrowsAsync(
async () => {
//@ts-ignore: subject missing on purpose
await nc.request();
},
NatsError,
"BAD_SUBJECT",
);
await cleanup(ns, nc);
});

Deno.test("basics - close promise resolves", async () => {
const lock = Lock();
const cs = new TestServer(false, (ca: Connection) => {
Expand Down

0 comments on commit ce4f4aa

Please sign in to comment.