Stage 3 · Build
API Design & gRPC
Error Contracts
Standardize REST problem+json, gRPC status codes, validation errors, and correlation IDs.
Why Error Contracts
Inconsistent error responses make API integration painful. Clients cannot reliably parse errors or determine the correct retry strategy. A consistent error contract lets clients handle errors programmatically.
problem+json
RFC 7807 defines a standard format for HTTP API errors. It includes a type URI, title, status code, detail message, and optional extensions. Use this format for all REST API errors.
gRPC Status Codes
| Code | Name | Use Case |
|---|---|---|
| 0 | OK | Success |
| 3 | INVALID_ARGUMENT | Bad request parameters |
| 4 | DEADLINE_EXCEEDED | Request timed out |
| 5 | NOT_FOUND | Resource does not exist |
| 6 | ALREADY_EXISTS | Duplicate creation |
| 7 | PERMISSION_DENIED | Authorization failure |
| 13 | INTERNAL | Server error |
| 14 | UNAVAILABLE | Service down |
| 16 | UNAUTHENTICATED | Missing or invalid credentials |
Validation Errors
Correlation IDs
Error Middleware
Treat error responses as part of your API contract. Document error codes, status codes, and response shapes. Breaking error responses are breaking API changes.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.