Skip to content

Commit 130f42a

Browse files
committed
- added test method which throws an error and CodedRpcException class which extends the RpcException
1 parent 46c2f87 commit 130f42a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test-handler.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from "@nestjs/common";
1414

1515
import { JSONRpcService } from ".";
16+
import { RpcException } from "@nestjs/microservices";
1617

1718
const initialModuleState = {
1819
pipeCalled: false,
@@ -77,4 +78,20 @@ export class TestService {
7778
console.log("Invoke WAS called");
7879
return params;
7980
}
81+
82+
@UsePipes(TestPipe)
83+
@UseInterceptors(TestInterceptor)
84+
@UseGuards(TestGuard)
85+
public async testError(params: any) {
86+
console.log("Throw an error !!!");
87+
88+
// construct the error object with some data inside
89+
throw new CodedRpcException("RPC EXCEPTION", 403, { fromService: "Test Service", params });
90+
}
91+
}
92+
93+
export class CodedRpcException extends RpcException {
94+
constructor(message: string, public code: number = 500, public data: any = {}) {
95+
super({ message, code, data });
96+
}
8097
}

0 commit comments

Comments
 (0)