Files
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
Press Run tests to start the app. Its log appears here.Graded endpoints
No error, nothing to translate: the reply passes through the operator untouched
The service throws RpcException({ status: 404, message }); the object crosses the wire as it is, and the gateway keeps its status
CatsService throws a NameTakenError, a plain domain error; the filter bound to the rename handler turns it into { status: 409, message }
The rename handler finds the cat first, so an unknown id is the same 404 as a lookup, not a crash on null
The rename succeeds and the reply is the renamed cat
The service answers a plain string, no status: the gateway says 502 Bad Gateway, the failure of the server behind it, and passes the message on
The adoption event from lesson 2 still flows
Luna is Nala now, Tom has an adopter, and a successful list passes through the operator as well