Skip to content

Commit 34f3e16

Browse files
committed
- removed console.logs, moved CodedRPCException to index.ts, removed comments
1 parent b239c28 commit 34f3e16

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

src/index.spec.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as request from "supertest";
33
import { Test } from "@nestjs/testing";
44
import { INestMicroservice } from "@nestjs/common";
55

6-
import { TestService, CodedRpcException } from "./test-handler";
6+
import { TestService } from "./test-handler";
77
import { JSONRPCServer } from ".";
88

99
describe("json-rpc-e2e", () => {
@@ -48,19 +48,6 @@ describe("json-rpc-e2e", () => {
4848
.send({ method: "test.testError", params: { data: "hi" } })
4949
.expect(403)
5050
.expect(errorObj);
51-
52-
// The testing with expect(req).rejects doesn't work
53-
54-
// const req = request(server.server)
55-
// .post("/rpc/v1")
56-
// .send({ method: "test.testError", params: { data: "hi" } });
57-
58-
// expect(req).rejects.toEqual(
59-
// new CodedRpcException("RPC EXCEPTION", 403, {
60-
// fromService: "Test Service",
61-
// params: { data: "hi" }
62-
// })
63-
//);
6451
});
6552

6653
afterAll(async () => {

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as express from "express";
22
import * as http from "http";
33

4-
import { Server, CustomTransportStrategy } from "@nestjs/microservices";
4+
import { Server, CustomTransportStrategy, RpcException } from "@nestjs/microservices";
55
import { Injectable, Controller } from "@nestjs/common";
66
import { MessagePattern } from "@nestjs/microservices";
77

@@ -73,8 +73,6 @@ export class JSONRPCServer extends Server implements CustomTransportStrategy {
7373
error => ({ error })
7474
);
7575

76-
console.log(response);
77-
7876
if ("error" in response) {
7977
let resp = { code: 500, message: response.error.message, data: undefined };
8078
if ("code" in response.error) resp.code = response.error.code;
@@ -101,3 +99,9 @@ export class JSONRPCServer extends Server implements CustomTransportStrategy {
10199
// do nothing, maybe block further requests
102100
}
103101
}
102+
103+
export class CodedRpcException extends RpcException {
104+
constructor(message: string, public code: number = 500, public data: any = {}) {
105+
super({ message, code, data });
106+
}
107+
}

src/test-handler.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import {
1212
Scope
1313
} from "@nestjs/common";
1414

15-
import { JSONRpcService } from ".";
16-
import { RpcException } from "@nestjs/microservices";
15+
import { JSONRpcService, CodedRpcException } from ".";
1716

1817
const initialModuleState = {
1918
pipeCalled: false,
@@ -83,15 +82,7 @@ export class TestService {
8382
@UseInterceptors(TestInterceptor)
8483
@UseGuards(TestGuard)
8584
public async testError(params: any) {
86-
console.log("Throw an error !!!");
87-
8885
// construct the error object with some data inside
8986
throw new CodedRpcException("RPC EXCEPTION", 403, { fromService: "Test Service", params });
9087
}
9188
}
92-
93-
export class CodedRpcException extends RpcException {
94-
constructor(message: string, public code: number = 500, public data: any = {}) {
95-
super({ message, code, data });
96-
}
97-
}

0 commit comments

Comments
 (0)