Skip to content

Commit af6706f

Browse files
authored
Merge pull request #91 from Procedure-RPC/dev
v0.13.1
2 parents 516847f + 697e9a9 commit af6706f

File tree

15 files changed

+4458
-2939
lines changed

15 files changed

+4458
-2939
lines changed

jest.config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"preset": "ts-jest",
3+
"injectGlobals": false,
4+
"restoreMocks": true,
35
"testEnvironment": "node",
46
"coverageReporters": ["html", "text", "cobertura", "json", "lcovonly"],
57
"coverageThreshold": {

package-lock.json

Lines changed: 2 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@procedure-rpc/procedure.js",
3-
"version": "0.13.0",
3+
"version": "0.13.1",
44
"title": "procedure.js",
55
"description": "The simple RPC framework for Node.js.",
66
"main": "./dist/index.js",

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,15 @@ export async function call<Output = unknown>(
629629
)
630630
: ping(endpoint, opts.ping, opts.ipv6, opts.signal));
631631
} catch (error) {
632-
throw error instanceof ProcedureTimedOutError
632+
const isTimeoutError = (error: unknown): boolean =>
633+
error instanceof ProcedureTimedOutError ||
634+
(error instanceof AggregateError &&
635+
error.errors.every(
636+
(e) =>
637+
e instanceof ProcedureTimedOutError ||
638+
isTimeoutError(e)
639+
));
640+
throw isTimeoutError(error)
633641
? new ProcedureNotFoundError() // timeout on ping = not found
634642
: error;
635643
}

test/errors.spec.ts

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { beforeEach, describe, expect, it } from '@jest/globals';
2+
13
import {
24
ProcedureError,
35
ProcedureUnknownError,
@@ -104,7 +106,9 @@ describe('ProcedureInternalClientError', () => {
104106
let instance: ProcedureInternalClientError;
105107

106108
describe('when no parameters passed', () => {
107-
beforeEach(() => (instance = new ProcedureInternalClientError()));
109+
beforeEach(() => {
110+
instance = new ProcedureInternalClientError();
111+
});
108112

109113
it('should be: instanceof ProcedureError', () => {
110114
expect(instance).toBeInstanceOf(ProcedureError);
@@ -725,35 +729,45 @@ describe('isError(object: unknown): object is Error', () => {
725729
});
726730

727731
describe('when object: undefined', () => {
728-
beforeEach(() => (object = undefined));
732+
beforeEach(() => {
733+
object = undefined;
734+
});
729735
it('should return: false', () => {
730736
expect(isError(object)).toEqual(false);
731737
});
732738
});
733739

734740
describe('when object: null', () => {
735-
beforeEach(() => (object = null));
741+
beforeEach(() => {
742+
object = null;
743+
});
736744
it('should return: false', () => {
737745
expect(isError(object)).toEqual(false);
738746
});
739747
});
740748

741749
describe('when object: instanceof TypeError', () => {
742-
beforeEach(() => (object = new TypeError()));
750+
beforeEach(() => {
751+
object = new TypeError();
752+
});
743753
it('should return: true', () => {
744754
expect(isError(object)).toEqual(true);
745755
});
746756
});
747757

748758
describe("when object: { name: 'Foo', message: 'Bar' }", () => {
749-
beforeEach(() => (object = { name: 'Foo', message: 'Bar' }));
759+
beforeEach(() => {
760+
object = { name: 'Foo', message: 'Bar' };
761+
});
750762
it('should return: true', () => {
751763
expect(isError(object)).toEqual(true);
752764
});
753765
});
754766

755767
describe("when object: { name: 'Foo' }", () => {
756-
beforeEach(() => (object = { name: 'Foo' }));
768+
beforeEach(() => {
769+
object = { name: 'Foo' };
770+
});
757771
it('should return: false', () => {
758772
expect(isError(object)).toEqual(false);
759773
});
@@ -763,73 +777,85 @@ describe('isError(object: unknown): object is Error', () => {
763777
describe('isProcedureError(object: unknown): object is ProcedureError', () => {
764778
let object: unknown;
765779
describe('when object: instanceof Error', () => {
766-
beforeEach(() => (object = new Error()));
780+
beforeEach(() => {
781+
object = new Error();
782+
});
767783
it('should return: false', () => {
768784
expect(isProcedureError(object)).toEqual(false);
769785
});
770786
});
771787

772788
describe('when object: undefined', () => {
773-
beforeEach(() => (object = undefined));
789+
beforeEach(() => {
790+
object = undefined;
791+
});
774792
it('should return: false', () => {
775793
expect(isProcedureError(object)).toEqual(false);
776794
});
777795
});
778796

779797
describe('when object: null', () => {
780-
beforeEach(() => (object = null));
798+
beforeEach(() => {
799+
object = null;
800+
});
781801
it('should return: false', () => {
782802
expect(isProcedureError(object)).toEqual(false);
783803
});
784804
});
785805

786806
describe('when object: instanceof TypeError', () => {
787-
beforeEach(() => (object = new TypeError()));
807+
beforeEach(() => {
808+
object = new TypeError();
809+
});
788810
it('should return: false', () => {
789811
expect(isProcedureError(object)).toEqual(false);
790812
});
791813
});
792814

793815
describe("when object: { name: 'Foo', message: 'Bar' }", () => {
794-
beforeEach(() => (object = { name: 'Foo', message: 'Bar' }));
816+
beforeEach(() => {
817+
object = { name: 'Foo', message: 'Bar' };
818+
});
795819
it('should return: false', () => {
796820
expect(isProcedureError(object)).toEqual(false);
797821
});
798822
});
799823

800824
describe("when object: { name: 'Foo' }", () => {
801-
beforeEach(() => (object = { name: 'Foo' }));
825+
beforeEach(() => {
826+
object = { name: 'Foo' };
827+
});
802828
it('should return: false', () => {
803829
expect(isProcedureError(object)).toEqual(false);
804830
});
805831
});
806832

807833
describe('when object: instanceof ProcedureError', () => {
808-
beforeEach(() => (object = new ProcedureUnknownError()));
834+
beforeEach(() => {
835+
object = new ProcedureUnknownError();
836+
});
809837
it('should return: true', () => {
810838
expect(isProcedureError(object)).toEqual(true);
811839
});
812840
});
813841

814842
describe("when object: { name: 'ProcedureError', message: 'foo', code: ProcedureErrorCodes.NOT_FOUND }", () => {
815-
beforeEach(
816-
() =>
817-
(object = {
818-
name: 'ProcedureError',
819-
message: 'foo',
820-
code: ProcedureErrorCodes.NOT_FOUND,
821-
})
822-
);
843+
beforeEach(() => {
844+
object = {
845+
name: 'ProcedureError',
846+
message: 'foo',
847+
code: ProcedureErrorCodes.NOT_FOUND,
848+
};
849+
});
823850
it('should return: true', () => {
824851
expect(isProcedureError(object)).toEqual(true);
825852
});
826853
});
827854

828855
describe("when object: { name: 'ProcedureError', message: 'foo', code: -1 }", () => {
829-
beforeEach(
830-
() =>
831-
(object = { name: 'ProcedureError', message: 'foo', code: -1 })
832-
);
856+
beforeEach(() => {
857+
object = { name: 'ProcedureError', message: 'foo', code: -1 };
858+
});
833859
it('should return: false', () => {
834860
expect(isProcedureError(object)).toEqual(false);
835861
});

0 commit comments

Comments
 (0)