Files
What you'll learn
- Bind pipes, guards and interceptors to message handlers exactly as to routes, and know they run in the same order: guards, interceptors, pipes, handler
- Validate a payload with ValidationPipe and an exceptionFactory that throws an RpcException, since its default BadRequestException means nothing to a transport
- Know that pipes only run on decorated parameters: a DTO needs @Payload() to be validated
- Read a message's data and handler in a guard or interceptor through ExecutionContext.switchToRpc() and getHandler()
Press Run tests to start the app. Its log appears here.Graded endpoints
The payload passes the ValidationPipe and the service creates the cat; the gateway only forwarded the body
The pipe refuses the payload with an RpcException listing every constraint that failed, and the gateway keeps the 400 and the list
StaffGuard finds no staffKey in the payload and refuses with its own RpcException, so the caller gets a 403 with a reason
A key that is not the staff key is refused the same way
The gateway put the x-staff-key header into the payload, the guard let the message through, and Luna is removed
The 404 from the previous lesson, which the interceptor sees fail
Oscar was created and Luna removed
The adoption event from lesson 2; interceptors apply to event handlers too
Tom's adopter is recorded: the event's payload arrived whole
Every handler the interceptor wrapped, in order, with its outcome. The two refused removals are missing: guards run before interceptors, so a refused message never reaches one. The failed validation is there: pipes run inside the interceptor