gRPC
gRPC Error Codes
ErrorValidateEasy
What you will learn
- status.details() contains rich error info via Any protobuf โ clients deserialize typed error payloads
- Standard error types (google.rpc.BadRequest, ErrorInfo) โ use these for interop, not custom message fields
- Test details serialization across languages โ Go / Python / Node clients must each deserialize the same bytes
Description
Handle different gRPC status codes (OK, NOT_FOUND, INVALID_ARGUMENT, etc.).
Test Scenario
// Request non-existent user
grpcurl -plaintext \
-d '{"id": "invalid-id"}' \
localhost:50051 \
practice.users.UserService/GetUser
// Expected error:
ERROR:
Code: NotFound
Message: User not found: invalid-idTesting Tips
- โขgRPC has standard status codes (not HTTP)
- โขCommon: OK, CANCELLED, INVALID_ARGUMENT, NOT_FOUND, PERMISSION_DENIED
- โขError details can include metadata
// Playwright API Testing - gRPC (via REST gateway)import { test, expect } from '@playwright/test';test('gRPC unary call via gateway', async ({ request }) => {const response = await request.post('/api/grpc/UserService/GetUser', {data: { id: '1' }});expect(response.ok()).toBeTruthy();const data = await response.json();expect(data.user).toBeDefined();});
Challenge ID: grpc-error-handling
2 frameworks available