Errors across the wire — Microservices · NestJS

What a thrown error becomes on the other side of a transport: RpcException for errors the caller can act on, an exception filter that turns a domain error into one, and a gateway that turns every reply's error into the right HTTP status.

What you will learn

Read the theory for Errors across the wire

All Microservices lessons

All NestJS courses

loading types…

What you'll learn

  • Throw RpcException for an error the caller should see, and know what it becomes on the wire: an object as it is, a string as { status: 'error', message }
  • Know why any other error, an HttpException included, reaches the caller only as 'Internal server error'
  • Write an RpcExceptionFilter whose catch() returns an erroring Observable, and bind it with @UseFilters
  • Translate reply errors into HTTP statuses at the gateway with an RxJS operator, including a 502 for failures the service did not explain