Throw RpcException on the microservice side to send structured errors back to the caller. On the API gateway or caller side, catch errors in the Observable pipeline with catchError() and rethrow as HTTP exceptions. Register a global RpcExceptionFilter to convert RpcException to HTTP responses on the gateway.
RpcException is the correct exception class for microservice handlers — plain Error objects are not serialized properly.
Pass an object to RpcException with statusCode and message for structured error payloads.
The gateway must have a global RpcExceptionFilter to convert RpcException to HTTP responses.
catchError() in the Observable pipeline intercepts errors from send() before they propagate as unhandled.
throwError(() => new HttpException(...)) re-throws as an HTTP exception so the gateway's exception filters handle it.