Skip to content

Commit bc5713d

Browse files
committed
feat(reactive-rpc): 🎸 improve error reporting
1 parent e7b9f4b commit bc5713d

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/server/__tests__/blocks.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ describe('blocks.*', () => {
7575
try {
7676
await call('blocks.get', {id: 'my-block'});
7777
throw new Error('not this error');
78-
} catch (err) {
79-
if (!(err instanceof Value)) throw err;
80-
const error = err.data;
81-
if (!(error instanceof RpcError)) throw err;
82-
expect(error.errno).toBe(RpcErrorCodes.NOT_FOUND);
78+
} catch (err: any) {
79+
expect(err.errno).toBe(RpcErrorCodes.NOT_FOUND);
8380
}
8481
});
8582
});

src/server/routes/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {TypeRouterCaller} from '../../reactive-rpc/common/rpc/caller/TypeRouterC
55
import {RpcError} from '../../reactive-rpc/common/rpc/caller';
66
import type {Services} from '../services/Services';
77
import type {RouteDeps} from './types';
8+
import {Value} from '../../reactive-rpc/common/messages/Value';
89

910
export const createRouter = (services: Services) => {
1011
const system = new TypeSystem();
@@ -18,8 +19,9 @@ export const createCaller = (services: Services) => {
1819
const caller = new TypeRouterCaller<typeof router>({
1920
router,
2021
wrapInternalError: (error: unknown) => {
21-
if (error instanceof RpcError) console.error(error.toJson());
22-
else console.error(error);
22+
if (error instanceof Value) return error;
23+
if (error instanceof RpcError) return RpcError.value(error);
24+
console.error(error);
2325
return RpcError.valueFrom(error);
2426
},
2527
});

0 commit comments

Comments
 (0)