HTTP status codes are integral to REST API applications and microservices. With the introduction of the gRPC framework, applications gained the ability to redefine their roles based on traditional protocol/RPC standards.
Effective error handling is crucial, prompting the need to convert gRPC status codes into their HTTP equivalents for seamless processing by REST API services. The table below outlines the corresponding status codes, enhancing the development workflow. For more in-depth information, refer to the gRPC-GateWay repository.
|-----------------------------|---------------------------|
| gRPC Status Code | HTTP Status Code |
|-----------------------------|---------------------------|
|`OK` (Code: 0) | 200 OK |
|`CANCELLED` (Code: 1) | 499 Client Closed Request |
|`UNKNOWN` (Code: 2) | 500 Internal Server Error |
|`INVALID_ARGUMENT` (Code: 3) | 400 Bad Request |
|`DEADLINE_EXCEEDED` (Code: 4)| 504 Gateway Timeout |
|`NOT_FOUND` (Code: 5) | 404 Not Found |
|`ALREADY_EXISTS` (Code: 6) | 409 Conflict |
|`PERMISSION_DENIED` (Code: 7)| 403 Forbidden |
|`RESOURCE_EXHAUSTED`(Code:8) | 429 Too Many Requests |
|`FAILED_PRECONDITION`(Code:9)| 400 Bad Request |
|`ABORTED` (Code: 10) | 409 Conflict |
|`OUT_OF_RANGE` (Code: 11) | 400 Bad Request |
|`UNIMPLEMENTED` (Code: 12) | 501 Not Implemented |
|`INTERNAL` (Code: 13) | 500 Internal Server Error |
|`UNAVAILABLE` (Code: 14) | 503 Service Unavailable |
|`DATA_LOSS` (Code: 15) | 500 Internal Server Error |
|-----------------------------|---------------------------|
Note that some gRPC status codes may not have a direct HTTP equivalent, and the mappings are based on best-fit scenarios. Additionally, gRPC status codes provide more granular information about the status of a request compared to HTTP status codes.
Top comments (0)