Pipes

Pipes

μ›Ή μ†ŒμΌ“ νŒŒμ΄ν”„μ™€ 일반 νŒŒμ΄ν”„ μ‚¬μ΄μ—λŠ” 차이가 μ—†μŠ΅λ‹ˆλ‹€. μ•Œμ•„μ•Ό ν•  μœ μΌν•œ 것은 HttpException을 λ°œμƒμ‹œν‚€λŠ” λŒ€μ‹  WsException을 μ‚¬μš©ν•΄μ•Ό ν•œλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. κ²Œλ‹€κ°€ λͺ¨λ“  νŒŒμ΄ν”„λŠ” data 맀개 λ³€μˆ˜μ—λ§Œ μ μš©λ©λ‹ˆλ‹€ (ν΄λΌμ΄μ–ΈνŠΈ μΈμŠ€ν„΄μŠ€μ˜ μ‚¬μš΄λ“œλ₯Ό ν™•μΈν•˜κ±°λ‚˜ λ³€ν˜•ν•˜κΈ° λ•Œλ¬Έμ— 어색함).

info 힌트 WsException ν΄λž˜μŠ€λŠ”@nestjs/websockets νŒ¨ν‚€μ§€μ—μ„œ λ…ΈμΆœλ©λ‹ˆλ‹€.

Binding pipes

λ‹€μŒμ€ μˆ˜λ™μœΌλ‘œ μΈμŠ€ν„΄μŠ€ν™” 된 λ©”μ†Œλ“œ λ²”μœ„ νŒŒμ΄ν”„λ₯Ό μ‚¬μš©ν•˜λŠ” μ˜ˆμž…λ‹ˆλ‹€ (클래슀 λ²”μœ„λ„ μž‘λ™ 함).

@@filename()
@UsePipes(new ValidationPipe())
@SubscribeMessage('events')
handleEvent(client: Client, data: unknown): WsResponse<unknown> {
  const event = 'events';
  return { event, data };
}
@@switch
@UsePipes(new ValidationPipe())
@SubscribeMessage('events')
handleEvent(client, data) {
  const event = 'events';
  return { event, data };
}

Last updated