Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-6459 Replace passing error handling in tldraw #5053

Merged
merged 18 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { TextEncoder } from 'util';
import { INestApplication, NotAcceptableException } from '@nestjs/common';
import { MongoMemoryDatabaseModule } from '@infra/database';
import { createConfigModuleOptions } from '@src/config';
import { Logger } from '@src/core/logger';
import { of, throwError } from 'rxjs';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { HttpService } from '@nestjs/axios';
import { AxiosError, AxiosHeaders, AxiosResponse } from 'axios';
import { axiosResponseFactory } from '@shared/testing';
import { CoreModule } from '@src/core';
import { TldrawRedisFactory, TldrawRedisService } from '../../redis';
import { TldrawDrawing } from '../../entities';
import { TldrawWsService } from '../../service';
Expand All @@ -22,6 +22,7 @@ import { TldrawWs } from '..';
import { WsCloseCode, WsCloseMessage } from '../../types';
import { TldrawConfig } from '../../config';

// This is a unit test, no api test...need to be refactored
describe('WebSocketController (WsAdapter)', () => {
let app: INestApplication;
let gateway: TldrawWs;
Expand All @@ -41,6 +42,7 @@ describe('WebSocketController (WsAdapter)', () => {
imports: [
MongoMemoryDatabaseModule.forRoot({ entities: [TldrawDrawing] }),
ConfigModule.forRoot(createConfigModuleOptions(tldrawTestConfig)),
CoreModule,
],
providers: [
TldrawWs,
Expand All @@ -54,10 +56,6 @@ describe('WebSocketController (WsAdapter)', () => {
provide: TldrawRepo,
useValue: createMock<TldrawRepo>(),
},
{
provide: Logger,
useValue: createMock<Logger>(),
},
{
provide: HttpService,
useValue: createMock<HttpService>(),
Expand All @@ -76,6 +74,7 @@ describe('WebSocketController (WsAdapter)', () => {

afterAll(async () => {
await app.close();
jest.resetAllMocks();
CeEv marked this conversation as resolved.
Show resolved Hide resolved
});

afterEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/modules/tldraw/controller/tldraw.ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
NotFoundException,
NotAcceptableException,
} from '@nestjs/common';
import { Logger } from '@src/core/logger';
import { isAxiosError } from 'axios';
import { firstValueFrom } from 'rxjs';
import { HttpService } from '@nestjs/axios';
import { DomainErrorHandler } from '@src/core';
import { WebsocketInitErrorLoggable } from '../loggable';
import { TldrawConfig, TLDRAW_SOCKET_PORT } from '../config';
import { WsCloseCode, WsCloseMessage } from '../types';
Expand All @@ -27,7 +27,7 @@ export class TldrawWs implements OnGatewayInit, OnGatewayConnection {
private readonly configService: ConfigService<TldrawConfig, true>,
private readonly tldrawWsService: TldrawWsService,
private readonly httpService: HttpService,
private readonly logger: Logger
private readonly domainErrorHandler: DomainErrorHandler
) {}

public async handleConnection(client: WebSocket, request: Request): Promise<void> {
Expand Down Expand Up @@ -106,7 +106,7 @@ export class TldrawWs implements OnGatewayInit, OnGatewayConnection {
err?: unknown
): void {
client.close(code, message);
this.logger.warning(new WebsocketInitErrorLoggable(code, message, docName, err));
this.domainErrorHandler.exec(new WebsocketInitErrorLoggable(code, message, docName, err));
}

private handleError(err: unknown, client: WebSocket, docName: string): void {
Expand Down
Loading
Loading