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

Observable errors from websocket @SubscribeMessage are not caught by exception filters, causing server crash #1285

Closed
zakhenry opened this issue Nov 13, 2018 · 4 comments

Comments

@zakhenry
Copy link

zakhenry commented Nov 13, 2018

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

If I return an observable that errors from within a @WebsocketGateway method that has @SubscribeMessage, the server crashes rather than invoking an error handler.

Expected behavior

Either the global error handler should catch the error and emit it to the client, or if set, the custom WsException.catch method should be invoked with the error.

Minimal reproduction of the problem with instructions

import { Injectable, UseFilters } from '@nestjs/common';
import { OnGatewayInit, SubscribeMessage, WebSocketGateway, WebSocketServer, WsResponse } from '@nestjs/websockets';
import { Observable, throwError } from 'rxjs';
import { map } from 'rxjs/operators';
import { Namespace, Socket } from 'socket.io';

@WebSocketGateway()
export class SocketGateway {

  @SubscribeMessage('ping')
  public pong(
    client: Socket,
    data: any,
  ): Observable<WsResponse<any>> {
    
    return throwError(); // this causes server crash, not a handled exception
  }
}

Environment


Nest version: 5.3.0
@zakhenry zakhenry changed the title Observable errors from websocket @SubscribeMessage are not caught by exception filters Observable errors from websocket @SubscribeMessage are not caught by exception filters, causing server crash Nov 13, 2018
@kamilmysliwiec
Copy link
Member

Thanks for reporting! Fixed by #1346

@zakhenry
Copy link
Author

zakhenry commented Dec 6, 2018

@kamilmysliwiec excellent thanks! Sorry it was a bit of a tough one to give a runnable repro for

@kamilmysliwiec
Copy link
Member

Fixed in 5.5.0 :)

@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants