forked from nestjs/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisconnected.controller.ts
More file actions
33 lines (32 loc) · 921 Bytes
/
Copy pathdisconnected.controller.ts
File metadata and controls
33 lines (32 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {
Controller,
Post,
Body,
RequestTimeoutException,
InternalServerErrorException,
} from '@nestjs/common';
import { Observable, throwError } from 'rxjs';
import { ClientProxyFactory } from '@nestjs/microservices';
import { tap, catchError } from 'rxjs/operators';
@Controller()
export class DisconnectedClientController {
@Post()
call(@Body() options): Observable<number> {
const client = ClientProxyFactory.create(options);
return client
.send<number, number[]>({ cmd: 'none' }, [1, 2, 3])
.pipe(
tap(
console.log.bind(console, 'data'),
console.error.bind(console, 'error'),
),
catchError(({ code }) =>
throwError(
code === 'ECONNREFUSED' || code === 'CONN_ERR'
? new RequestTimeoutException('ECONNREFUSED')
: new InternalServerErrorException(),
),
),
);
}
}